mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-09 09:51:02 +01: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:
parent
f29afc7cf7
commit
8541027d40
@ -7,7 +7,8 @@ export class Response {
|
|||||||
if (typeof (error) === 'string') {
|
if (typeof (error) === 'string') {
|
||||||
res.message = error;
|
res.message = error;
|
||||||
} else {
|
} else {
|
||||||
res.message = error.message != null ? error.message : error.toString();
|
res.message = error.message != null ? error.message :
|
||||||
|
error.toString() === '[object Object]' ? JSON.stringify(error) : error.toString();
|
||||||
}
|
}
|
||||||
res.data = data;
|
res.data = data;
|
||||||
return res;
|
return res;
|
||||||
|
@ -1282,6 +1282,8 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
let responseJson: any = null;
|
let responseJson: any = null;
|
||||||
if (this.isJsonResponse(response)) {
|
if (this.isJsonResponse(response)) {
|
||||||
responseJson = await response.json();
|
responseJson = await response.json();
|
||||||
|
} else if (this.isTextResponse(response)) {
|
||||||
|
responseJson = {Message: await response.text()};
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ErrorResponse(responseJson, response.status, tokenError);
|
return new ErrorResponse(responseJson, response.status, tokenError);
|
||||||
@ -1357,4 +1359,9 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
const typeHeader = response.headers.get('content-type');
|
const typeHeader = response.headers.get('content-type');
|
||||||
return typeHeader != null && typeHeader.indexOf('application/json') > -1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user