fix(backend): better notes/translate error response (#13631)

* fix(backend): better `notes/translate` error response

* Update CHANGELOG.md

* test(backend): perform administrative operations as `root`

---------

Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
zyoshoka
2024-03-30 13:51:53 +09:00
committed by GitHub
parent f3500ffda9
commit b35ae97ba7
4 changed files with 97 additions and 28 deletions

View File

@@ -21,7 +21,7 @@ export const meta = {
res: {
type: 'object',
optional: false, nullable: false,
optional: true, nullable: false,
properties: {
sourceLang: { type: 'string' },
text: { type: 'string' },
@@ -39,6 +39,11 @@ export const meta = {
code: 'NO_SUCH_NOTE',
id: 'bea9b03f-36e0-49c5-a4db-627a029f8971',
},
cannotTranslateInvisibleNote: {
message: 'Cannot translate invisible note.',
code: 'CANNOT_TRANSLATE_INVISIBLE_NOTE',
id: 'ea29f2ca-c368-43b3-aaf1-5ac3e74bbe5d',
},
},
} as const;
@@ -72,17 +77,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
if (!(await this.noteEntityService.isVisibleForMe(note, me.id))) {
return 204; // TODO: 良い感じのエラー返す
throw new ApiError(meta.errors.cannotTranslateInvisibleNote);
}
if (note.text == null) {
return 204;
return;
}
const instance = await this.metaService.fetch();
if (instance.deeplAuthKey == null) {
return 204; // TODO: 良い感じのエラー返す
throw new ApiError(meta.errors.unavailable);
}
let targetLang = ps.targetLang;