mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-16 15:07:36 -07:00
API: Better error response
This commit is contained in:
parent
ab8a730c5e
commit
cd439c770e
2 changed files with 12 additions and 2 deletions
|
@ -62,7 +62,15 @@ export default (endpoint: string, user: IUser, app: IApp, data: any, file?: any)
|
|||
console.warn(`SLOW API CALL DETECTED: ${ep.name} (${time}ms)`);
|
||||
}
|
||||
} catch (e) {
|
||||
rej(e.message);
|
||||
if (e.name == 'INVALID_PARAM') {
|
||||
rej({
|
||||
code: e.name,
|
||||
param: e.param,
|
||||
reason: e.message
|
||||
});
|
||||
} else {
|
||||
rej(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@ export default function <T extends Defs>(defs: T, params: any): [{
|
|||
Object.keys(defs.params).some(k => {
|
||||
const [v, e] = defs.params[k].get(params[k]);
|
||||
if (e) {
|
||||
err = e;
|
||||
err = new Error(e.message);
|
||||
err.name = 'INVALID_PARAM';
|
||||
(err as any).param = k;
|
||||
return true;
|
||||
} else {
|
||||
if (v === undefined && defs.params[k].data.default) {
|
||||
|
|
Loading…
Reference in a new issue