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:
parent
fc52e95ad0
commit
2756f553c6
181 changed files with 2010 additions and 1322 deletions
|
|
@ -5,6 +5,7 @@ import Following from '../../../../models/following';
|
|||
import { pack } from '../../../../models/user';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
|
@ -47,10 +48,18 @@ export const meta = {
|
|||
validator: $.optional.bool,
|
||||
default: false,
|
||||
}
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: 'No such user.',
|
||||
code: 'NO_SUCH_USER',
|
||||
id: '27fa5435-88ab-43de-9360-387de88727cd'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
export default define(meta, async (ps, me) => {
|
||||
const q: any = ps.userId != null
|
||||
? { _id: ps.userId }
|
||||
: { usernameLower: ps.username.toLowerCase(), host: ps.host };
|
||||
|
|
@ -58,10 +67,9 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
|||
const user = await User.findOne(q);
|
||||
|
||||
if (user === null) {
|
||||
return rej('user not found');
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
}
|
||||
|
||||
// Construct query
|
||||
const query = {
|
||||
followeeId: user._id
|
||||
} as any;
|
||||
|
|
@ -98,8 +106,8 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
|||
|
||||
const users = await Promise.all(following.map(f => pack(f.followerId, me, { detail: true })));
|
||||
|
||||
res({
|
||||
return {
|
||||
users: users,
|
||||
next: inStock ? following[following.length - 1]._id : null,
|
||||
});
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue