Improve network error handling

This commit is contained in:
Ken Hibino
2021-01-26 21:25:42 -08:00
parent 1bee405599
commit a6498ca729
13 changed files with 288 additions and 104 deletions

View File

@@ -1,7 +1,7 @@
import { AxiosError } from "axios";
// toErrorString returns a string representaion of axios error.
export function toErrorString(error: AxiosError<string>): string {
// toErrorStringWithHttpStatus returns a string representaion of axios error with HTTP status.
export function toErrorStringWithHttpStatus(error: AxiosError<string>): string {
const { response } = error;
if (!response) {
return "error: no error response data available";
@@ -9,6 +9,15 @@ export function toErrorString(error: AxiosError<string>): string {
return `${response.status} (${response.statusText}): ${response.data}`;
}
// toErrorString returns a string representaion of axios error.
export function toErrorString(error: AxiosError<string>): string {
const { response } = error;
if (!response) {
return "Unknown error occurred. See the logs for details.";
}
return response.data;
}
interface Duration {
hour: number;
minute: number;