25 lines
695 B
JavaScript
25 lines
695 B
JavaScript
// Generated, do not edit. sha256:312aacc2f42215e3ffe54763edfbe29f7affc0f2ae41d522eaebbe359f2b2ffa
|
|
export class AppError extends Error {
|
|
constructor(key, params = null, fallback = null) {
|
|
super(fallback || key);
|
|
this.name = 'AppError';
|
|
this.key = key;
|
|
this.params = params;
|
|
}
|
|
}
|
|
|
|
export const isAppError = (e) => !!e && typeof e === 'object' && typeof e.key === 'string';
|
|
|
|
export function fail(key, params = null, fallback = null) {
|
|
throw new AppError(key, params, fallback);
|
|
}
|
|
|
|
export function errorPayload(e) {
|
|
const uit = { error: (e && e.message) || String(e) };
|
|
if (isAppError(e)) {
|
|
uit.key = e.key;
|
|
if (e.params) uit.params = e.params;
|
|
}
|
|
return uit;
|
|
}
|