Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
1.1 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { LocalizerService } from './../services/localizer.service';
export class ErrorDto {
constructor(
public readonly statusCode: number,
public readonly message: string,
public readonly details: ReadonlyArray<string> = [],
public readonly inner?: any
) {
}
public translate(localizer: LocalizerService) {
let result = appendLast(localizer.getOrKey(this.message), '.');
if (this.details && this.details.length > 0) {
result += '\n\n';
for (const detail of this.details) {
const translated = localizer.getOrKey(detail);
result += ` * ${appendLast(translated, '.')}\n`;
}
}
return result;
}
public toString() {
return `ErrorDto(${JSON.stringify(this)})`;
}
}
function appendLast(row: string, char: string) {
const last = row[row.length - 1];
if (last !== char) {
return row + char;
} else {
return row;
}
}