add renderInlineError to serialize errors in a consistent way
This commit is contained in:
parent
3808502f86
commit
61d0aeba2e
4 changed files with 42 additions and 36 deletions
35
packages/backend/src/misc/render-inline-error.ts
Normal file
35
packages/backend/src/misc/render-inline-error.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { StatusError } from '@/misc/status-error.js';
|
||||
|
||||
export function renderInlineError(err: unknown): string {
|
||||
if (err instanceof IdentifiableError) {
|
||||
if (err.message) {
|
||||
return `${err.name} ${err.id}: ${err.message}`;
|
||||
} else {
|
||||
return `${err.name} ${err.id}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (err instanceof StatusError) {
|
||||
if (err.message) {
|
||||
return `${err.name} ${err.statusCode}: ${err.message}`;
|
||||
} else {
|
||||
return `${err.name} ${err.statusCode}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (err instanceof Error) {
|
||||
if (err.message) {
|
||||
return `${err.name}: ${err.message}`;
|
||||
} else {
|
||||
return err.name;
|
||||
}
|
||||
}
|
||||
|
||||
return String(err);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue