2017-07-13 11:39:07 -07:00
|
|
|
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
|
|
|
|
}) {
|
|
|
|
err[_handledError] = { type, message, redirectTo };
|
|
|
|
return err;
|
|
|
|
}
|
2017-12-27 10:11:17 -08:00
|
|
|
|
|
|
|
export const createValidatorErrorFormatter = (type, redirectTo) =>
|
|
|
|
({ msg }) => wrapHandledError(
|
|
|
|
new Error(msg),
|
|
|
|
{
|
|
|
|
type,
|
|
|
|
message: msg,
|
|
|
|
redirectTo
|
|
|
|
}
|
|
|
|
);
|