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:
@@ -3,6 +3,7 @@ import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import { pack } from '../../../../models/user';
|
||||
import { removePinned } from '../../../../services/i/pin';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@@ -24,22 +25,24 @@ export const meta = {
|
||||
'en-US': 'Target note ID'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchNote: {
|
||||
message: 'No such note.',
|
||||
code: 'NO_SUCH_NOTE',
|
||||
id: '454170ce-9d63-4a43-9da1-ea10afe81e21'
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Processing
|
||||
try {
|
||||
await removePinned(user, ps.noteId);
|
||||
} catch (e) {
|
||||
return rej(e.message);
|
||||
}
|
||||
|
||||
// Serialize
|
||||
const iObj = await pack(user, user, {
|
||||
detail: true
|
||||
export default define(meta, async (ps, user) => {
|
||||
await removePinned(user, ps.noteId).catch(e => {
|
||||
if (e.id === 'b302d4cf-c050-400a-bbb3-be208681f40c') throw new ApiError(meta.errors.noSuchNote);
|
||||
throw e;
|
||||
});
|
||||
|
||||
// Send response
|
||||
res(iObj);
|
||||
}));
|
||||
return await pack(user, user, {
|
||||
detail: true
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user