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

mozilla / blurts-server / fc5fd966-32ac-4dce-a653-c3228ccbd2bc

pending completion
fc5fd966-32ac-4dce-a653-c3228ccbd2bc

Pull #2762

circleci

GitHub
Merge pull request #2751 from mozilla/MNTOR-1025
Pull Request #2762: Merge `main` into `localization`

282 of 1122 branches covered (25.13%)

Branch coverage included in aggregate %.

203 of 203 new or added lines in 19 files covered. (100.0%)

959 of 3014 relevant lines covered (31.82%)

5.13 hits per line

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

0.0
/src/middleware/error.js
1
import { MethodNotAllowedError, NotFoundError } from '../utils/error.js'
2
import mozlog from '../utils/log.js'
3
const log = mozlog('middleware')
×
4

5
/**
6
 * Generic error handling function that takes in an error with
7
 *
8
 * message: error message
9
 *
10
 * statusCode: http status code
11
 *
12
 * and returns a json response
13
 * @param {object} err error object [ message, statusCode ]
14
 * @param {object} req request object
15
 * @param {object} res response object
16
 * @param {object} next middleware callback
17
 */
18
function errorHandler (err, req, res, next) {
19
  log.error('error', err.stack)
×
20
  const errStatus = err.statusCode || 500
×
21
  const errMsg = err.message || 'Empty error message'
×
22
  res.status(errStatus).json({
×
23
    success: false,
24
    status: errStatus,
25
    message: process.env.NODE_ENV !== 'production' ? errMsg : 'Something went wrong', // hide error message when in production
×
26
    stack: process.env.NODE_ENV === 'dev' ? err.stack : {} // hide stack when not in dev
×
27
  })
28
}
29

30
/**
31
 * Used as a 404 default for routes
32
 */
33
function notFound (req) {
34
  // TODO: when there's a 404 page to be rendered here,
35
  // replace the json return with html
36
  throw new NotFoundError(`Page not found! ${req.method} ${req.originalUrl}`)
×
37
}
38

39
function methodNotAllowed (req) {
40
  throw new MethodNotAllowedError(`Method not allowed: ${req.method} ${req.originalUrl}`)
×
41
}
42

43
export {
44
  errorHandler,
45
  notFound,
46
  methodNotAllowed
47
}
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