diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2019-02-22 11:46:58 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-22 11:46:58 +0900 |
| commit | 2756f553c68082342a784ef716c62da6cea6f3ca (patch) | |
| tree | 1e0364ca9ddc1fd88e311f0687746f44e007effd /src/services/note/reaction/create.ts | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-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/services/note/reaction/create.ts')
| -rw-r--r-- | src/services/note/reaction/create.ts | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/services/note/reaction/create.ts b/src/services/note/reaction/create.ts index cf72927642..5897df2c97 100644 --- a/src/services/note/reaction/create.ts +++ b/src/services/note/reaction/create.ts @@ -9,31 +9,28 @@ import renderLike from '../../../remote/activitypub/renderer/like'; import { deliver } from '../../../queue'; import { renderActivity } from '../../../remote/activitypub/renderer'; import perUserReactionsChart from '../../../services/chart/per-user-reactions'; +import { IdentifiableError } from '../../../misc/identifiable-error'; -export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => { +export default async (user: IUser, note: INote, reaction: string) => { // Myself if (note.userId.equals(user._id)) { - return rej('cannot react to my note'); + throw new IdentifiableError('2d8e7297-1873-4c00-8404-792c68d7bef0', 'cannot react to my note'); } // Create reaction - try { - await NoteReaction.insert({ - createdAt: new Date(), - noteId: note._id, - userId: user._id, - reaction - }); - } catch (e) { + await NoteReaction.insert({ + createdAt: new Date(), + noteId: note._id, + userId: user._id, + reaction + }).catch(e => { // duplicate key error if (e.code === 11000) { - return rej('already reacted'); + throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298', 'already reacted'); } - return rej('something happened'); - } - - res(); + throw e; + }); // Increment reactions count await Note.update({ _id: note._id }, { @@ -89,4 +86,6 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise deliver(user, content, note._user.inbox); } //#endregion -}); + + return; +}; |