Show error alert when data is not available

This commit is contained in:
Ken Hibino
2021-01-09 13:48:49 -08:00
parent 933127cc0e
commit 251b262798
13 changed files with 230 additions and 123 deletions

View File

@@ -1,3 +1,4 @@
import { Dispatch } from "redux";
import {
deleteQueue,
listQueues,
@@ -5,11 +6,12 @@ import {
pauseQueue,
resumeQueue,
} from "../api";
import { Dispatch } from "redux";
import { toErrorString } from "../utils";
// List of queue related action types.
export const LIST_QUEUES_BEGIN = "LIST_QUEUES_BEGIN";
export const LIST_QUEUES_SUCCESS = "LIST_QUEUES_SUCCESS";
export const LIST_QUEUES_ERROR = "LIST_QUEUES_ERROR";
export const DELETE_QUEUE_BEGIN = "DELETE_QUEUE_BEGIN";
export const DELETE_QUEUE_SUCCESS = "DELETE_QUEUE_SUCCESS";
export const DELETE_QUEUE_ERROR = "DELETE_QUEUE_ERROR";
@@ -29,6 +31,11 @@ interface ListQueuesSuccessAction {
payload: ListQueuesResponse;
}
interface ListQueuesErrorAction {
type: typeof LIST_QUEUES_ERROR;
error: string;
}
interface DeleteQueueBeginAction {
type: typeof DELETE_QUEUE_BEGIN;
queue: string; // name of the queue
@@ -81,6 +88,7 @@ interface ResumeQueueErrorAction {
export type QueuesActionTypes =
| ListQueuesBeginAction
| ListQueuesSuccessAction
| ListQueuesErrorAction
| DeleteQueueBeginAction
| DeleteQueueSuccessAction
| DeleteQueueErrorAction
@@ -94,12 +102,19 @@ export type QueuesActionTypes =
export function listQueuesAsync() {
return async (dispatch: Dispatch<QueuesActionTypes>) => {
dispatch({ type: LIST_QUEUES_BEGIN });
// TODO: try/catch and dispatch error action on failure
const response = await listQueues();
dispatch({
type: LIST_QUEUES_SUCCESS,
payload: response,
});
try {
const response = await listQueues();
dispatch({
type: LIST_QUEUES_SUCCESS,
payload: response,
});
} catch (error) {
console.error(`listQueuesAsync: ${toErrorString(error)}`);
dispatch({
type: LIST_QUEUES_ERROR,
error: error.response.data,
});
}
};
}

View File

@@ -1,5 +1,6 @@
import { Dispatch } from "redux";
import { getRedisInfo, RedisInfoResponse } from "../api";
import { toErrorString } from "../utils";
// List of redis-info related action types.
export const GET_REDIS_INFO_BEGIN = "GET_REDIS_INFO_BEGIN";
@@ -33,10 +34,10 @@ export function getRedisInfoAsync() {
const response = await getRedisInfo();
dispatch({ type: GET_REDIS_INFO_SUCCESS, payload: response });
} catch (error) {
console.error("getRedisInfoAsync: ", error);
console.error(`getRedisInfoAsync: ${toErrorString(error)}`);
dispatch({
type: GET_REDIS_INFO_BEGIN,
error: "Could not fetch redis info",
type: GET_REDIS_INFO_ERROR,
error: error.response.data,
});
}
};

View File

@@ -5,6 +5,7 @@ import {
listSchedulerEntries,
ListSchedulerEntriesResponse,
} from "../api";
import { toErrorString } from "../utils";
// List of scheduler-entry related action types.
export const LIST_SCHEDULER_ENTRIES_BEGIN = "LIST_SCHEDULER_ENTRIES_BEGIN";
@@ -67,10 +68,10 @@ export function listSchedulerEntriesAsync() {
payload: response,
});
} catch (error) {
console.error(error);
console.error(`listSchedulerEnqueueEventsAsync: ${toErrorString(error)}`);
dispatch({
type: LIST_SCHEDULER_ENTRIES_ERROR,
error: "Could not retrieve scheduler entries",
error: error.response.data,
});
}
};

View File

@@ -1,5 +1,6 @@
import { Dispatch } from "redux";
import { listServers, ListServersResponse } from "../api";
import { toErrorString } from "../utils";
// List of server related action types.
export const LIST_SERVERS_BEGIN = "LIST_SERVERS_BEGIN";
@@ -34,10 +35,10 @@ export function listServersAsync() {
payload: response,
});
} catch (error) {
console.error("listServersAsync: ", error);
console.error(`listServersAsync: ${toErrorString(error)}`);
dispatch({
type: LIST_SERVERS_ERROR,
error: "Could not retrieve servers info",
error: error.response.data,
});
}
};