1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-02 00:38:14 +09:00

API: Better error response

This commit is contained in:
syuilo 2018-10-26 14:38:34 +09:00
parent f8a7f9378a
commit 02b47f963c
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
2 changed files with 12 additions and 2 deletions

View File

@ -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)`); console.warn(`SLOW API CALL DETECTED: ${ep.name} (${time}ms)`);
} }
} catch (e) { } catch (e) {
rej(e.message); if (e.name == 'INVALID_PARAM') {
rej({
code: e.name,
param: e.param,
reason: e.message
});
} else {
rej(e);
}
return; return;
} }

View File

@ -12,7 +12,9 @@ export default function <T extends Defs>(defs: T, params: any): [{
Object.keys(defs.params).some(k => { Object.keys(defs.params).some(k => {
const [v, e] = defs.params[k].get(params[k]); const [v, e] = defs.params[k].get(params[k]);
if (e) { if (e) {
err = e; err = new Error(e.message);
err.name = 'INVALID_PARAM';
(err as any).param = k;
return true; return true;
} else { } else {
if (v === undefined && defs.params[k].data.default) { if (v === undefined && defs.params[k].data.default) {