library for error responses in json
- npm install json_error_response (minimum working version: 1.0.3)
https://www.npmjs.com/package/json_error_response
-
IsRequired (string itemName)
-
IsNotObject (string itemName, string type)
-
OutOfBound (string itemName, int startPoint, int endPoint)
-
Unauthorized ()
-
PermissionDenied ()
-
Forbidden ()
-
NotImpemented ()
-
SizeNegative ()
-
NotFound (string itemName)
-
DefaultError (string error, response res)
- This can be used as a default error from the try catch.
const json_error = require("json_error_response");
console.log(json_error.IsRequired("user"))
// => {"message": "user not found"};
- return res.json(json_error.isRequired("user"));
try {
// do something
} catch (err) {
json_error.DefaultError(err, res);
}