mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Handle response.body if it is not JSON (#3599)
This commit is contained in:
parent
c36bf38f46
commit
cc73f2d5a4
4 changed files with 11 additions and 9 deletions
1
changes/1469-improve-error-handling
Normal file
1
changes/1469-improve-error-handling
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Improve error handling when response body is not JSON
|
||||
|
|
@ -69,7 +69,7 @@ describe(
|
|||
|
||||
// Go to host details page
|
||||
cy.location("pathname").should("match", /hosts\/[0-9]/i);
|
||||
cy.getAttached("span.status").should("contain", /online/i);
|
||||
cy.getAttached(".status--online").should("exist");
|
||||
|
||||
// Run policy on host
|
||||
let policyname = "";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
import { IPack } from "interfaces/pack";
|
||||
import { IScheduledQuery } from "interfaces/scheduled_query";
|
||||
import { IGlobalScheduledQuery } from "interfaces/global_scheduled_query";
|
||||
|
||||
export default {
|
||||
ACTIVITIES: "/v1/fleet/activities",
|
||||
CHANGE_PASSWORD: "/v1/fleet/change_password",
|
||||
|
|
|
|||
|
|
@ -44,10 +44,15 @@ export default class Request {
|
|||
send() {
|
||||
const { endpoint, requestAttributes } = this;
|
||||
|
||||
return fetch(endpoint, requestAttributes).then((response) => {
|
||||
return response.json().then((jsonResponse) => {
|
||||
return Request.handleResponse(response, jsonResponse);
|
||||
});
|
||||
return fetch(endpoint, requestAttributes).then(async (response) => {
|
||||
let jsonResponse;
|
||||
try {
|
||||
jsonResponse = await response.json();
|
||||
} catch (error) {
|
||||
console.log("Failed to parse response body as JSON: ", error);
|
||||
throw response.statusText || error;
|
||||
}
|
||||
return Request.handleResponse(response, jsonResponse);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue