mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
parse validation errors from error response model
This commit is contained in:
@@ -23,16 +23,38 @@ export class ErrorResponse {
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
if (this.validationErrors == null) {
|
||||
return this.message;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
getAllMessages(): string[] {
|
||||
const messages: string[] = [];
|
||||
if (this.validationErrors == null) {
|
||||
return messages;
|
||||
}
|
||||
for (const key in this.validationErrors) {
|
||||
if (!this.validationErrors.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
this.validationErrors[key].forEach((item: string) => {
|
||||
let prefix = '';
|
||||
if (key.indexOf('[') > -1 && key.indexOf(']') > -1) {
|
||||
const lastSep = key.lastIndexOf('.');
|
||||
prefix = key.substr(0, lastSep > -1 ? lastSep : key.length) + ': ';
|
||||
}
|
||||
messages.push(prefix + item);
|
||||
});
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user