try{
//code
} catch (err) {
return serverError(res, err);
}
function serverReturnError(res: ResponseTy, err: ErrorTy): void {
if (err.name === 'ForbiddenError') {
return res.forbidden({message: "Not enough rights", name: "Forbidden"});
} else if (err.name === 'UsageError') {
if (err.code === 'E_UNIQUE') {
return res.status(409).json({
name: err.code,
message: err.message,
details: {...err.detail, removed: !!err.detail.removed}