From c1f4b34b91fda8ab9132634b9968623676e4d721 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Tue, 28 Aug 2018 22:07:06 -0400 Subject: [PATCH] Update compositor.json via compositor.io --- compositor.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compositor.json b/compositor.json index 37b561f..d06f3c9 100644 --- a/compositor.json +++ b/compositor.json @@ -124,7 +124,7 @@ "metadata": { "source": "github.readme" }, - "html": "\n

Package for normalizing api errors using the following format:

\n

\n

Install

\n
npm install wcp-errors

Usage

\n
const { notFound } = require('wcp-errors');\nbadRequest('first name is required.');

Examples (ExpressJS)

\n
app.get('/not_found', function(req, res, next) {\n  next(notFound());\n});\n\n// Bad request example\napp.get('/bad_request', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request', new Error(), {\n      type: 'parameter',\n      name: 'Eek',\n    })\n  );\n});\n\napp.get('/multiple_errors', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request').add({\n      code: 'bad_request',\n      message: ':-(',\n    })\n  );\n});\n\n// Throw! example\napp.get('/throws', function(req, res, next) {\n  throw new Error('Oh noes!');\n});\n\n// Error handler\napp.use(function(err, req, res, next) {\n  if (err instanceof ApiError) {\n    res.status(err.statusCode).json(err);\n  } else {\n    res.status(500).json(internalServerError(err.message, err));\n  }\n});

Run the examples

\n\n

Open a browser and try:

\n\n

APIs

\n

Basic

\n

All basic Apis take the following three optional arguments:

\n\n

All APIs

\n
badRequest();\nconflict();\nforbidden();\ninternalServerError();\nmethodNotAllowed();\nnotAcceptable();\nnotFound();\nrequestEntityTooLarge();\nunAuthorized();\nunsupportedMediaType();

Optionally, add additional errors to a wcp error

\n
// Create an error and add additional error(s) to the wcp error\nbadRequest().add({\n  code = 'validation_error', // optional\n  message = 'last name required.', // optional\n  target, // optional target\n  error // optional error object\n})

Raw

\n

The raw API is only necessary in circumstances where the Basic are not sufficient.

\n
 const { ApiError } = require('wcp-errors');\n\n// Manually create a new API error\nconst e = new ApiError({\n  statusCode: 409,\n  code: 'conflict',\n  message,\n  error, // optional error\n  target, // optional target\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 1', // optional\n  target, // optional target\n  error // optional error object\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 2', // optional\n  target, // optional target\n  error // optional error object\n})

TODO

\n\n

Contributers

\n

Contributers are welcome! Please submit a PR.

\n

License

\n

MIT

\n" + "html": "\n

Package for normalizing api errors using the following format:

\n

\n

Install

\n
npm install wcp-errors

Usage

\n
const { notFound } = require('wcp-errors');\nbadRequest('first name is required.');

Examples (ExpressJS)

\n
app.get('/not_found', function(req, res, next) {\n  next(notFound());\n});\n\n// Bad request example\napp.get('/bad_request', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request', new Error(), {\n      type: 'parameter',\n      name: 'Eek',\n    })\n  );\n});\n\napp.get('/multiple_errors', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request').add({\n      code: 'bad_request',\n      message: ':-(',\n    })\n  );\n});\n\n// Throw! example\napp.get('/throws', function(req, res, next) {\n  throw new Error('Oh noes!');\n});\n\n// Error handler\napp.use(function(err, req, res, next) {\n  if (err instanceof ApiError) {\n    res.status(err.statusCode).json(err);\n  } else {\n    res.status(500).json(internalServerError(err.message, err));\n  }\n});

Run the examples

\n\n

Open a browser and try:

\n\n

APIs

\n

Basic

\n

All basic Apis take the following three optional arguments:

\n\n

All APIs

\n
badRequest();\nconflict();\nforbidden();\ninternalServerError();\nmethodNotAllowed();\nnotAcceptable();\nnotFound();\nrequestEntityTooLarge();\nunAuthorized();\nunsupportedMediaType();

Optionally, add additional errors to a wcp error

\n
// Create an error and add additional error(s) to the wcp error\nbadRequest().add({\n  code = 'validation_error', // optional\n  message = 'last name required.', // optional\n  target, // optional target\n  error // optional error object\n})

Raw

\n

The raw API is only necessary in circumstances where the Basic are not sufficient.

\n
 const { ApiError } = require('wcp-errors');\n\n// Manually create a new API error\nconst e = new ApiError({\n  statusCode: 409,\n  code: 'conflict',\n  message,\n  error, // optional error\n  target, // optional target\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 1', // optional\n  target, // optional target\n  error // optional error object\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 2', // optional\n  target, // optional target\n  error // optional error object\n})

TODO

\n\n

Contributers

\n

Contributers are welcome! Please submit a PR.

\n

License

\n

MIT

\n" }, { "component": "footer",