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:
syuilo
2019-02-22 11:46:58 +09:00
committed by GitHub
parent fc52e95ad0
commit 2756f553c6
181 changed files with 2010 additions and 1322 deletions

View File

@@ -1,8 +1,9 @@
import $ from 'cafy';
import ID, { transform } from '../../../../../misc/cafy-id';
import Note from '../../../../../models/note';
import define from '../../../define';
import unwatch from '../../../../../services/note/unwatch';
import { getValiedNote } from '../../../common/getters';
import { ApiError } from '../../../error';
export const meta = {
stability: 'stable',
@@ -25,21 +26,22 @@ export const meta = {
'en-US': 'Target note ID.'
}
}
},
errors: {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: '09b3695c-f72c-4731-a428-7cff825fc82e'
}
}
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Get note
const note = await Note.findOne({
_id: ps.noteId
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;
});
if (note === null) {
return rej('note not found');
}
await unwatch(user._id, note);
// Send response
res();
}));
});