WIP: Testing offline detection on staging
parent
193e1c3f09
commit
bd493f2e06
|
@ -14,7 +14,7 @@ import { AxiosRequestConfig, AxiosResponse } from "axios";
|
|||
import { Content } from "./constants";
|
||||
|
||||
export function responseFulfilled(input: AxiosResponse): AxiosResponse {
|
||||
let method = input.config.method;
|
||||
const method = input.config.method;
|
||||
if (method && METHODS.includes(method)) {
|
||||
notifyBotOfChanges(input.config.url, METHOD_MAP[method]);
|
||||
}
|
||||
|
@ -22,17 +22,20 @@ export function responseFulfilled(input: AxiosResponse): AxiosResponse {
|
|||
}
|
||||
|
||||
export function responseRejected(x: SafeError | undefined) {
|
||||
|
||||
if (x && _.isUndefined(x.response)) {
|
||||
console.error("YOU ARE PROBABLY OFFLINE RIGHT NOW");
|
||||
Promise.reject(x);
|
||||
}
|
||||
if (x && isSafeError(x)) {
|
||||
let a = ![451, 401, 422].includes(x.response.status);
|
||||
let b = x.response.status > 399;
|
||||
const a = ![451, 401, 422].includes(x.response.status);
|
||||
const b = x.response.status > 399;
|
||||
// Openfarm API was sending too many 404's.
|
||||
let c = !_.get(x, "response.config.url", "").includes("openfarm.cc/");
|
||||
const c = !_.get(x, "response.config.url", "").includes("openfarm.cc/");
|
||||
|
||||
if (a && b && c) {
|
||||
setTimeout(() => {
|
||||
// Explicitly throw error so error reporting tool will save it.
|
||||
let msg = `Bad response: ${x.response.status} ${JSON.stringify(x.response)}`;
|
||||
const msg = `Bad response: ${x.response.status} ${JSON.stringify(x.response)}`;
|
||||
throw new Error(msg);
|
||||
}, 1);
|
||||
}
|
||||
|
@ -58,11 +61,11 @@ export function responseRejected(x: SafeError | undefined) {
|
|||
|
||||
export function requestFulfilled(auth: AuthState) {
|
||||
return (config: AxiosRequestConfig) => {
|
||||
let req = config.url || "";
|
||||
let isAPIRequest = req.includes(API.current.baseUrl);
|
||||
const req = config.url || "";
|
||||
const isAPIRequest = req.includes(API.current.baseUrl);
|
||||
if (isAPIRequest) {
|
||||
config.headers = config.headers || {};
|
||||
let headers = (config.headers as
|
||||
const headers = (config.headers as
|
||||
{ Authorization: string | undefined });
|
||||
headers.Authorization = auth.token.encoded || "CANT_FIND_TOKEN";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue