• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #13275

pending completion
#13275

push

circleci

rhelmer
MNTOR-1452 - use UPDATE FOR to lock table and prevent race condition when adding email

282 of 1679 branches covered (16.8%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

959 of 4548 relevant lines covered (21.09%)

1.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/middleware/error.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import { MethodNotAllowedError } from '../utils/error.js'
6
import mozlog from '../utils/log.js'
7
import { guestLayout } from '../views/guestLayout.js'
8
import { error } from '../views/partials/error.js'
9
const log = mozlog('middleware')
×
10

11
/**
12
 * Generic error handling function that takes in an error with
13
 *
14
 * message: error message
15
 *
16
 * statusCode: http status code
17
 *
18
 * and returns a json response
19
 *
20
 * @param {object} err error object [ message, statusCode ]
21
 * @param {object} req request object
22
 * @param {object} res response object
23
 * @param {object} next middleware callback
24
 */
25
function errorHandler (err, req, res, next) {
26
  log.error('error', err.stack)
×
27
  const errStatus = err.statusCode || 500
×
28
  const errMsg = err.message || 'Empty error message'
×
29

30
  if (req.accepts('text/html') === 'text/html') {
×
31
    res.status(errStatus).send(guestLayout({
×
32
      partial: error,
33
      statusCode: errStatus
34
    }))
35
    return
×
36
  }
37

38
  res.status(errStatus).json({
×
39
    success: false,
40
    status: errStatus,
41
    message: process.env.NODE_ENV !== 'production' ? errMsg : 'Something went wrong', // hide error message when in production
×
42
    stack: process.env.NODE_ENV === 'dev' ? err.stack : {} // hide stack when not in dev
×
43
  })
44
}
45

46
/**
47
 * Log 404 errors, but don't send a response - they're handled by the `notFound` view
48
 *
49
 * @param req
50
 * @param _res
51
 * @param next
52
 */
53
function notFound (req, _res, next) {
54
  log.info('http-error', { statusCode: 404, method: req.method, originalUrl: req.originalUrl })
×
55
  next()
×
56
}
57

58
function methodNotAllowed (req) {
59
  throw new MethodNotAllowedError(`Method not allowed: ${req.method} ${req.originalUrl}`)
×
60
}
61

62
export {
63
  errorHandler,
64
  notFound,
65
  methodNotAllowed
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc