mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
export class ErrorResponse {
|
|
message: string;
|
|
validationErrors: { [key: string]: string[]; };
|
|
statusCode: number;
|
|
|
|
constructor(response: any, status: number, identityResponse?: boolean) {
|
|
let errorModel = null;
|
|
if (identityResponse && response && response.ErrorModel) {
|
|
errorModel = response.ErrorModel;
|
|
} else if (response) {
|
|
errorModel = response;
|
|
}
|
|
|
|
if (errorModel) {
|
|
this.message = errorModel.Message;
|
|
this.validationErrors = errorModel.ValidationErrors;
|
|
} else {
|
|
if (status === 429) {
|
|
this.message = 'Rate limit exceeded. Try again later.';
|
|
}
|
|
}
|
|
this.statusCode = status;
|
|
}
|
|
|
|
getSingleMessage(): string {
|
|
if (this.validationErrors) {
|
|
for (const key in this.validationErrors) {
|
|
if (!this.validationErrors.hasOwnProperty(key)) {
|
|
continue;
|
|
}
|
|
if (this.validationErrors[key].length) {
|
|
return this.validationErrors[key][0];
|
|
}
|
|
}
|
|
}
|
|
return this.message;
|
|
}
|
|
}
|