mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-23 03:03:46 -05:00
* chore(deps): update dependency prettier to v2.3.0 * chore: apply formating per prettier * fix: correctly disable import/no-unresolved Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Mrugesh Mohapatra <hi@mrugesh.dev> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
30 lines
677 B
JavaScript
30 lines
677 B
JavaScript
const _handledError = Symbol('handledError');
|
|
|
|
export function isHandledError(err) {
|
|
return !!err[_handledError];
|
|
}
|
|
|
|
export function unwrapHandledError(err) {
|
|
return err[_handledError] || {};
|
|
}
|
|
|
|
export function wrapHandledError(
|
|
err,
|
|
{ type, message, redirectTo, status = 200 }
|
|
) {
|
|
err[_handledError] = { type, message, redirectTo, status };
|
|
return err;
|
|
}
|
|
|
|
// for use with express-validator error formatter
|
|
export const createValidatorErrorFormatter =
|
|
(type, redirectTo) =>
|
|
({ msg }) =>
|
|
wrapHandledError(new Error(msg), {
|
|
type,
|
|
message: msg,
|
|
redirectTo,
|
|
// we default to 400 as these are malformed requests
|
|
status: 400
|
|
});
|