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

@@ -7,6 +7,7 @@ import renderAdd from '../../remote/activitypub/renderer/add';
import renderRemove from '../../remote/activitypub/renderer/remove';
import { renderActivity } from '../../remote/activitypub/renderer';
import { deliver } from '../../queue';
import { IdentifiableError } from '../../misc/identifiable-error';
/**
* 指定した投稿をピン留めします
@@ -21,7 +22,7 @@ export async function addPinned(user: IUser, noteId: mongo.ObjectID) {
});
if (note === null) {
throw new Error('note not found');
throw new IdentifiableError('70c4e51f-5bea-449c-a030-53bee3cce202', 'No such note.');
}
let pinnedNoteIds = user.pinnedNoteIds || [];
@@ -35,11 +36,11 @@ export async function addPinned(user: IUser, noteId: mongo.ObjectID) {
//#endregion
if (pinnedNoteIds.length >= 5) {
throw new Error('cannot pin more notes');
throw new IdentifiableError('15a018eb-58e5-4da1-93be-330fcc5e4e1a', 'You can not pin notes any more.');
}
if (pinnedNoteIds.some(id => id.equals(note._id))) {
throw new Error('already exists');
throw new IdentifiableError('23f0cf4e-59a3-4276-a91d-61a5891c1514', 'That note has already been pinned.');
}
pinnedNoteIds.unshift(note._id);
@@ -69,7 +70,7 @@ export async function removePinned(user: IUser, noteId: mongo.ObjectID) {
});
if (note === null) {
throw new Error('note not found');
throw new IdentifiableError('b302d4cf-c050-400a-bbb3-be208681f40c', 'No such note.');
}
const pinnedNoteIds = (user.pinnedNoteIds || []).filter(id => !id.equals(note._id));