Improve error handling of API (#4345)
* wip
* wip
* wip
* Update attached_notes.ts
* wip
* Refactor
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update call.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* ✌️
* Fix
This commit is contained in:
@ -4,6 +4,7 @@ import App from '../../../../../models/app';
|
||||
import AuthSess from '../../../../../models/auth-session';
|
||||
import config from '../../../../../config';
|
||||
import define from '../../../define';
|
||||
import { ApiError } from '../../../error';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
@ -12,17 +13,25 @@ export const meta = {
|
||||
appSecret: {
|
||||
validator: $.str
|
||||
}
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchApp: {
|
||||
message: 'No such app.',
|
||||
code: 'NO_SUCH_APP',
|
||||
id: '92f93e63-428e-4f2f-a5a4-39e1407fe998'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
export default define(meta, async (ps) => {
|
||||
// Lookup app
|
||||
const app = await App.findOne({
|
||||
secret: ps.appSecret
|
||||
});
|
||||
|
||||
if (app == null) {
|
||||
return rej('app not found');
|
||||
throw new ApiError(meta.errors.noSuchApp);
|
||||
}
|
||||
|
||||
// Generate token
|
||||
@ -35,9 +44,8 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
token: token
|
||||
});
|
||||
|
||||
// Response
|
||||
res({
|
||||
return {
|
||||
token: doc.token,
|
||||
url: `${config.auth_url}/${doc.token}`
|
||||
});
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user