summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes/renotes.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-02-22 11:46:58 +0900
committerGitHub <noreply@github.com>2019-02-22 11:46:58 +0900
commit2756f553c68082342a784ef716c62da6cea6f3ca (patch)
tree1e0364ca9ddc1fd88e311f0687746f44e007effd /src/server/api/endpoints/notes/renotes.ts
parentUpdate CHANGELOG.md (diff)
downloadmisskey-2756f553c68082342a784ef716c62da6cea6f3ca.tar.gz
misskey-2756f553c68082342a784ef716c62da6cea6f3ca.tar.bz2
misskey-2756f553c68082342a784ef716c62da6cea6f3ca.zip
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 * :v: * Fix
Diffstat (limited to 'src/server/api/endpoints/notes/renotes.ts')
-rw-r--r--src/server/api/endpoints/notes/renotes.ts40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/server/api/endpoints/notes/renotes.ts b/src/server/api/endpoints/notes/renotes.ts
index 531953540f..9873f1bffa 100644
--- a/src/server/api/endpoints/notes/renotes.ts
+++ b/src/server/api/endpoints/notes/renotes.ts
@@ -2,6 +2,8 @@ import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id';
import Note, { packMany } from '../../../../models/note';
import define from '../../define';
+import { getValiedNote } from '../../common/getters';
+import { ApiError } from '../../error';
export const meta = {
desc: {
@@ -35,24 +37,23 @@ export const meta = {
validator: $.optional.type(ID),
transform: transform,
}
- }
-};
+ },
-export default define(meta, (ps, user) => new Promise(async (res, rej) => {
- // Check if both of sinceId and untilId is specified
- if (ps.sinceId && ps.untilId) {
- return rej('cannot set sinceId and untilId');
+ errors: {
+ noSuchNote: {
+ message: 'No such note.',
+ code: 'NO_SUCH_NOTE',
+ id: '12908022-2e21-46cd-ba6a-3edaf6093f46'
+ }
}
+};
- // Lookup 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');
- }
-
const sort = {
_id: -1
};
@@ -72,11 +73,10 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
};
}
- const renotes = await Note
- .find(query, {
- limit: ps.limit,
- sort: sort
- });
+ const renotes = await Note.find(query, {
+ limit: ps.limit,
+ sort: sort
+ });
- res(await packMany(renotes, user));
-}));
+ return await packMany(renotes, user);
+});