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:
@@ -27,7 +27,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
export default define(meta, async (ps, user) => {
|
||||
// Generate secret
|
||||
const secret = rndstr('a-zA-Z0-9', 32);
|
||||
|
||||
@@ -42,9 +42,8 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
secret: secret
|
||||
});
|
||||
|
||||
// Response
|
||||
res(await pack(app, null, {
|
||||
return await pack(app, null, {
|
||||
detail: true,
|
||||
includeSecret: true
|
||||
}));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -2,6 +2,7 @@ import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import App, { pack } from '../../../../models/app';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
|
||||
export const meta = {
|
||||
params: {
|
||||
@@ -9,22 +10,29 @@ export const meta = {
|
||||
validator: $.type(ID),
|
||||
transform: transform
|
||||
},
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchApp: {
|
||||
message: 'No such app.',
|
||||
code: 'NO_SUCH_APP',
|
||||
id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
||||
export default define(meta, async (ps, user, app) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
// Lookup app
|
||||
const ap = await App.findOne({ _id: ps.appId });
|
||||
|
||||
if (ap === null) {
|
||||
return rej('app not found');
|
||||
throw new ApiError(meta.errors.noSuchApp);
|
||||
}
|
||||
|
||||
// Send response
|
||||
res(await pack(ap, user, {
|
||||
return await pack(ap, user, {
|
||||
detail: true,
|
||||
includeSecret: isSecure && ap.userId.equals(user._id)
|
||||
}));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user