⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@gayanMatch
Copy link

Description

Implements standardized error codes for Express-thrown errors as proposed in #6951.

Changes

  • Add lib/errors.js with error code constants and factory helpers
  • Expose express.errorCodes (frozen object) for programmatic error handling
  • Add code property to all 15 errors thrown by Express
  • Use Error.captureStackTrace for clean stack traces
  • Add tests for error codes

Error Codes

Code Location
ERR_INVALID_STATUS_CODE res.status()
ERR_STATUS_CODE_OUT_OF_RANGE res.status()
ERR_SENDFILE_PATH_REQUIRED res.sendFile()
ERR_SENDFILE_PATH_NOT_STRING res.sendFile()
ERR_SENDFILE_PATH_NOT_ABSOLUTE res.sendFile()
ERR_CONTENT_TYPE_ARRAY res.set()
ERR_COOKIE_SECRET_REQUIRED res.cookie()
ERR_MIDDLEWARE_REQUIRED app.use()
ERR_ENGINE_CALLBACK_REQUIRED app.engine()
ERR_HEADER_NAME_REQUIRED req.get()
ERR_HEADER_NAME_NOT_STRING req.get()
ERR_NO_DEFAULT_ENGINE View
ERR_VIEW_ENGINE_NOT_FOUND View
ERR_INVALID_ETAG_OPTION app.set('etag')
ERR_INVALID_QUERY_PARSER_OPTION app.set('query parser')

Usage

const express = require('express');
const { errorCodes } = express;

app.use((err, req, res, next) => {
  if (err.code === errorCodes.ERR_INVALID_STATUS_CODE) {
    // handle programmatically
  }
});

Closes #6951


Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=132382032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize on error codes for errors express throws

1 participant