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
|
|
@ -1,11 +1,10 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import define from '../../../define';
|
||||
import * as ms from 'ms';
|
||||
import deleteReaction from '../../../../../services/note/reaction/delete';
|
||||
import { IUser } from '../../../../../models/user';
|
||||
import { getValiedNote } from '../../../common/getters';
|
||||
import { ApiError } from '../../../error';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
|
@ -32,15 +31,30 @@ export const meta = {
|
|||
'en-US': 'Target note ID'
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchNote: {
|
||||
message: 'No such note.',
|
||||
code: 'NO_SUCH_NOTE',
|
||||
id: '764d9fce-f9f2-4a0e-92b1-6ceac9a7ad37'
|
||||
},
|
||||
|
||||
notReacted: {
|
||||
message: 'You are not reacting to that note.',
|
||||
code: 'NOT_REACTED',
|
||||
id: '92f4426d-4196-4125-aa5b-02943e2ec8fc'
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise((res, rej) => {
|
||||
deleteReactionById(user, ps.noteId)
|
||||
.then(r => res(r)).catch(e => rej(e));
|
||||
}));
|
||||
|
||||
async function deleteReactionById(user: IUser, noteId: mongo.ObjectID) {
|
||||
const note = await getValiedNote(noteId);
|
||||
await deleteReaction(user, note);
|
||||
}
|
||||
export default define(meta, async (ps, user) => {
|
||||
const note = await getValiedNote(ps.noteId).catch(e => {
|
||||
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||
throw e;
|
||||
});
|
||||
await deleteReaction(user, note).catch(e => {
|
||||
if (e.id === '60527ec9-b4cb-4a88-a6bd-32d3ad26817d') throw new ApiError(meta.errors.notReacted);
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue