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

mozilla / blurts-server / #12323

pending completion
#12323

push

circleci

Vinnl
Add a 404 error page

282 of 1373 branches covered (20.54%)

Branch coverage included in aggregate %.

14 of 14 new or added lines in 5 files covered. (100.0%)

959 of 3720 relevant lines covered (25.78%)

2.09 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
const log = mozlog('middleware')
×
8

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

34
/**
35
 * Log 404 errors, but don't send a response - they're handled by the `notFound` view
36
 */
37
function notFound (req, _res, next) {
38
  log.info('http-error', { statusCode: 404, method: req.method, originalUrl: req.originalUrl })
×
39
  next()
×
40
}
41

42
function methodNotAllowed (req) {
43
  throw new MethodNotAllowedError(`Method not allowed: ${req.method} ${req.originalUrl}`)
×
44
}
45

46
export {
47
  errorHandler,
48
  notFound,
49
  methodNotAllowed
50
}
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