Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
response-format
Advanced tools
Response Format
Module which provides HTTP-friendly error objects
Author: Gaurav Joshi
create(statusCode, [error, message, data])
success([message, data])
badRequest([message, data])
unAuthorized([message, data])
forbidden([message, data])
notFound([message, data])
notAllowed([message, data])
requestTimeout([message, data])
internalError([message, data])
badGateway([message, data])
unavailable([message, data])
gatewayTimeout([message, data])
const Format = require('response-format');
Each utility returns an Object which includes the following properties:
error
- true, false or null (if not specified).statusCode
- the HTTP status code.message
- string containing message (if not specified will return a pre-defined set of messages according to status code )data
- response payload (null in case of blank or error)create(statusCode, [error, message, data])
Generates a decorated response object where:
statusCode
- an HTTP error code number.message
- optional message string.data
- response payload.error
- true, false or null (if not specified).success([message, data])
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.Format.success();
Generates the following response payload:
{
"statusCode": 200,
"error": false,
"message": "OK",
"data": null
}
badRequest([message, data])
Returns a 400 Error where:
statusCode
- 400error
- truemessage
- optional message.data
- optional payload.Format.badRequest();
Generates the following response payload:
{
"statusCode": 400,
"error": true,
"message": "Bad Request",
"data": null
}
unAuthorized([message, data])
Returns a 402 Error where:
statusCode
- 402error
- truemessage
- optional message.data
- optional payload.Format.unAuthorized();
Generates the following response payload:
{
"statusCode": 402,
"error": true,
"message": "Unauthorized",
"data": null
}
forbidden([message, data])
Returns a 403 Error where:
statusCode
- 403error
- truemessage
- optional message.data
- optional payload.Format.forbidden();
Generates the following response payload:
{
"statusCode": 403,
"error": true,
"message": "Forbidden",
"data": null
}
notFound([message, data])
Returns a 404 Error where:
statusCode
- 404error
- truemessage
- optional message.data
- optional payload.Format.notFound();
Generates the following response payload:
{
"statusCode": 404,
"error": true,
"message": "Not Found",
"data": null
}
notAllowed([message, data])
Returns a 405 Error where:
statusCode
- 405error
- truemessage
- optional message.data
- optional payload.Format.notAllowed();
Generates the following response payload:
{
"statusCode": 405,
"error": true,
"message": "Method Not Allowed",
"data": null
}
requestTimeout([message, data])
Returns a 408 Error where:
statusCode
- 408error
- truemessage
- optional message.data
- optional payload.Format.requestTimeout();
Generates the following response payload:
{
"statusCode": 408,
"error": true,
"message": "Request Timeout",
"data": null
}
internalError([message, data])
Returns a 500 Error where:
statusCode
- 500error
- truemessage
- optional message.data
- optional payload.Format.internalError();
Generates the following response payload:
{
"statusCode": 500,
"error": true,
"message": "Internal Server Error",
"data": null
}
badGateway([message, data])
Returns a 502 Error where:
statusCode
- 502error
- truemessage
- optional message.data
- optional payload.Format.badGateway();
Generates the following response payload:
{
"statusCode": 502,
"error": true,
"message": "Bad Gateway",
"data": null
}
unavailable([message, data])
Returns a 503 Error where:
statusCode
- 503error
- truemessage
- optional message.data
- optional payload.Format.unavailable();
Generates the following response payload:
{
"statusCode": 503,
"error": true,
"message": "Service Unavailable",
"data": null
}
gatewayTimeout([message, data])
Returns a 504 Error where:
statusCode
- 504error
- truemessage
- optional message.data
- optional payload.Format.gatewayTimeout();
Generates the following response payload:
{
"statusCode": 504,
"error": true,
"message": "Gateway Timeout",
"data": null
}
FAQs
Module which will provide HTTP-friendly error objects
The npm package response-format receives a total of 173 weekly downloads. As such, response-format popularity was classified as not popular.
We found that response-format demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.