More granular error responses
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
// @flow
|
||||
import httpErrors from 'http-errors';
|
||||
|
||||
const apiError = (code: number, id: string, message: string) => {
|
||||
return httpErrors(code, message, { id });
|
||||
};
|
||||
export function ValidationError(message: string = 'Validation failed') {
|
||||
return httpErrors(400, message, { id: 'validation_error' });
|
||||
}
|
||||
|
||||
export default apiError;
|
||||
export { httpErrors };
|
||||
export function ParamRequiredError(
|
||||
message: string = 'Required parameter missing'
|
||||
) {
|
||||
return httpErrors(400, message, { id: 'param_required' });
|
||||
}
|
||||
|
||||
export function AuthorizationError(
|
||||
message: string = 'You do not have permission to access this resource'
|
||||
) {
|
||||
return httpErrors(403, message, { id: 'permission_required' });
|
||||
}
|
||||
|
||||
export function AdminRequiredError(
|
||||
message: string = 'An admin role is required to access this resource'
|
||||
) {
|
||||
return httpErrors(403, message, { id: 'admin_required' });
|
||||
}
|
||||
|
||||
export function NotFoundError(message: string = 'Resource not found') {
|
||||
return httpErrors(404, message, { id: 'not_found' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user