1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Handle text response errors (#301)

* Parse text error response to json Message field

* Do not output object.toString, prefer object serialization
This commit is contained in:
Matt Gibson
2021-03-09 10:58:17 -06:00
committed by GitHub
parent f29afc7cf7
commit 8541027d40
2 changed files with 9 additions and 1 deletions

View File

@@ -1282,6 +1282,8 @@ export class ApiService implements ApiServiceAbstraction {
let responseJson: any = null;
if (this.isJsonResponse(response)) {
responseJson = await response.json();
} else if (this.isTextResponse(response)) {
responseJson = {Message: await response.text()};
}
return new ErrorResponse(responseJson, response.status, tokenError);
@@ -1357,4 +1359,9 @@ export class ApiService implements ApiServiceAbstraction {
const typeHeader = response.headers.get('content-type');
return typeHeader != null && typeHeader.indexOf('application/json') > -1;
}
private isTextResponse(response: Response): boolean {
const typeHeader = response.headers.get('content-type');
return typeHeader != null && typeHeader.indexOf('text') > -1;
}
}