Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,24 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in new issue
Block a user