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

@@ -4,6 +4,7 @@ import Message from '../../../../../models/messaging-message';
import define from '../../../define';
import { publishMessagingStream } from '../../../../../services/stream';
import * as ms from 'ms';
import { ApiError } from '../../../error';
export const meta = {
stability: 'stable',
@@ -32,17 +33,25 @@ export const meta = {
'en-US': 'Target message ID.'
}
}
},
errors: {
noSuchMessage: {
message: 'No such message.',
code: 'NO_SUCH_MESSAGE',
id: '54b5b326-7925-42cf-8019-130fda8b56af'
},
}
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
export default define(meta, async (ps, user) => {
const message = await Message.findOne({
_id: ps.messageId,
userId: user._id
});
if (message === null) {
return rej('message not found');
throw new ApiError(meta.errors.noSuchMessage);
}
await Message.remove({ _id: message._id });
@@ -50,5 +59,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
publishMessagingStream(message.userId, message.recipientId, 'deleted', message._id);
publishMessagingStream(message.recipientId, message.userId, 'deleted', message._id);
res();
}));
return;
});