misskey/src/server/api/endpoints/users/lists/show.ts
syuilo 2756f553c6
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
2019-02-22 11:46:58 +09:00

46 lines
911 B
TypeScript

import $ from 'cafy';
import ID, { transform } from '../../../../../misc/cafy-id';
import UserList, { pack } from '../../../../../models/user-list';
import define from '../../../define';
import { ApiError } from '../../../error';
export const meta = {
desc: {
'ja-JP': '指定したユーザーリストの情報を取得します。',
'en-US': 'Show a user list.'
},
requireCredential: true,
kind: 'account-read',
params: {
listId: {
validator: $.type(ID),
transform: transform,
},
},
errors: {
noSuchList: {
message: 'No such list.',
code: 'NO_SUCH_LIST',
id: '7bc05c21-1d7a-41ae-88f1-66820f4dc686'
},
}
};
export default define(meta, async (ps, me) => {
// Fetch the list
const userList = await UserList.findOne({
_id: ps.listId,
userId: me._id,
});
if (userList == null) {
throw new ApiError(meta.errors.noSuchList);
}
return await pack(userList);
});