Add connectivity stats to state tree
parent
bd493f2e06
commit
1dc13f5f58
|
@ -8,7 +8,6 @@ jest.mock("../../../session", () => {
|
|||
return mockStorj[k];
|
||||
},
|
||||
invertBool: (k: string) => {
|
||||
console.log(`${k} will go from ${mockStorj[k]} to ${!mockStorj[k]}`);
|
||||
mockStorj[k] = !mockStorj[k];
|
||||
return mockStorj[k];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { Actions } from "../constants";
|
||||
|
||||
export function networkUp(payload = (new Date()).toJSON()) {
|
||||
return {
|
||||
type: Actions.NETWORK_UP,
|
||||
payload
|
||||
};
|
||||
}
|
||||
|
||||
export function networkDown(payload = (new Date()).toJSON()) {
|
||||
return {
|
||||
type: Actions.NETWORK_DOWN,
|
||||
payload
|
||||
};
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export interface APIStatus {
|
||||
state: "up" | "down";
|
||||
at: string;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { generateReducer } from "../redux/generate_reducer";
|
||||
import { Actions } from "../constants";
|
||||
import { APIStatus } from "./interfaces";
|
||||
|
||||
type State = APIStatus | undefined;
|
||||
|
||||
export let connectivityReducer = generateReducer<State>(undefined)
|
||||
.add<string>(Actions.NETWORK_UP, (s, { payload }) => {
|
||||
return { state: "up", at: payload };
|
||||
})
|
||||
.add<string>(Actions.NETWORK_DOWN, (s, { payload }) => {
|
||||
return { state: "down", at: payload };
|
||||
});
|
|
@ -425,4 +425,7 @@ export enum Actions {
|
|||
// Farmware
|
||||
SELECT_IMAGE = "SELECT_IMAGE",
|
||||
|
||||
// Network
|
||||
NETWORK_UP = "NETWORK_UP",
|
||||
NETWORK_DOWN = "NETWORK_DOWN"
|
||||
}
|
||||
|
|
|
@ -22,10 +22,6 @@ 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)) {
|
||||
const a = ![451, 401, 422].includes(x.response.status);
|
||||
const b = x.response.status > 399;
|
||||
|
@ -54,7 +50,7 @@ export function responseRejected(x: SafeError | undefined) {
|
|||
}
|
||||
return Promise.reject(x);
|
||||
} else {
|
||||
console.warn("GOT MALFORMED HTTP REJECTION?? This shouldn't happen!");
|
||||
console.error("YOU ARE PROBABLY OFFLINE RIGHT NOW");
|
||||
return Promise.reject(x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { Color as FarmBotJsColor } from "farmbot";
|
|||
import { DraggableState } from "./draggable/interfaces";
|
||||
import { PeripheralState } from "./controls/peripherals/interfaces";
|
||||
import { RestResources } from "./resources/interfaces";
|
||||
import { APIStatus } from "./connectivity/interfaces";
|
||||
|
||||
/** Regimens and sequences may have a "color" which determines how it looks
|
||||
in the UI. Only certain colors are valid. */
|
||||
|
@ -46,6 +47,7 @@ interface Location {
|
|||
}
|
||||
|
||||
export interface Everything {
|
||||
connectivity?: APIStatus;
|
||||
config: ConfigState;
|
||||
auth: AuthState | undefined;
|
||||
dispatch: Function;
|
||||
|
@ -63,6 +65,7 @@ export interface Everything {
|
|||
* In those cases, we can use the `UnsafeError` type instead of `any`, just to
|
||||
* quiet down the linter and to let others know it is inherently unsafe.
|
||||
*/
|
||||
// tslint:disable-next-line:no-any
|
||||
export type UnsafeError = any;
|
||||
|
||||
interface BasePoint {
|
||||
|
|
|
@ -8,8 +8,10 @@ import { Session } from "../session";
|
|||
import { resourceReducer as resources } from "../resources/reducer";
|
||||
import { Everything } from "../interfaces";
|
||||
import { Actions } from "../constants";
|
||||
import { connectivityReducer as connectivity } from "../connectivity/reducer";
|
||||
|
||||
export let reducers = combineReducers({
|
||||
connectivity,
|
||||
auth,
|
||||
bot,
|
||||
config,
|
||||
|
|
|
@ -67,8 +67,7 @@ function safelyFetchErrors(err: AxiosErrorResponse): Dictionary<string> {
|
|||
if (err && err.response && err.response.data) {
|
||||
return err.response.data;
|
||||
} else {
|
||||
console.log(t("Last error message wasn't formatted like an API error."));
|
||||
console.dir(err);
|
||||
console.log("TODO: Set status to `offline` here?");
|
||||
return {
|
||||
error: t("Your web browser is unable to communicate with the " +
|
||||
"web app server. Make sure you are connected to the Internet.")
|
||||
|
|
Loading…
Reference in New Issue