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
|
|
@ -3,6 +3,7 @@ import ID, { transform } from '../../../../misc/cafy-id';
|
|||
import User from '../../../../models/user';
|
||||
import Mute from '../../../../models/mute';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
|
@ -23,15 +24,35 @@ export const meta = {
|
|||
'en-US': 'Target user ID'
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: 'No such user.',
|
||||
code: 'NO_SUCH_USER',
|
||||
id: '6fef56f3-e765-4957-88e5-c6f65329b8a5'
|
||||
},
|
||||
|
||||
muteeIsYourself: {
|
||||
message: 'Mutee is yourself.',
|
||||
code: 'MUTEE_IS_YOURSELF',
|
||||
id: 'a4619cb2-5f23-484b-9301-94c903074e10'
|
||||
},
|
||||
|
||||
alreadyMuting: {
|
||||
message: 'You are already muting that user.',
|
||||
code: 'ALREADY_MUTING',
|
||||
id: '7e7359cb-160c-4956-b08f-4d1c653cd007'
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
export default define(meta, async (ps, user) => {
|
||||
const muter = user;
|
||||
|
||||
// 自分自身
|
||||
if (user._id.equals(ps.userId)) {
|
||||
return rej('mutee is yourself');
|
||||
throw new ApiError(meta.errors.muteeIsYourself);
|
||||
}
|
||||
|
||||
// Get mutee
|
||||
|
|
@ -45,7 +66,7 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
if (mutee === null) {
|
||||
return rej('user not found');
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
}
|
||||
|
||||
// Check if already muting
|
||||
|
|
@ -55,7 +76,7 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
if (exist !== null) {
|
||||
return rej('already muting');
|
||||
throw new ApiError(meta.errors.alreadyMuting);
|
||||
}
|
||||
|
||||
// Create mute
|
||||
|
|
@ -65,5 +86,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||
muteeId: mutee._id,
|
||||
});
|
||||
|
||||
res();
|
||||
}));
|
||||
return;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue