show error popup

This commit is contained in:
Stepan Usatiuk
2023-12-30 12:44:47 +01:00
parent bf8a2a3123
commit ffdddaf647

View File

@@ -1,6 +1,7 @@
// import { apiRoot } from "~src/env"; // import { apiRoot } from "~src/env";
import { jwtDecode } from "jwt-decode"; import { jwtDecode } from "jwt-decode";
import { isError } from "./dto";
const apiRoot: string = "http://localhost:8080"; const apiRoot: string = "http://localhost:8080";
@@ -59,7 +60,11 @@ export async function fetchJSON<T, P extends { parse: (arg: string) => T }>(
const json = await response.json().catch(() => { const json = await response.json().catch(() => {
return {}; return {};
}); });
return parser.parse(json); const parsed = parser.parse(json);
if (isError(parsed)) {
alert(parsed.errors.join(", "));
}
return parsed;
} }
export async function fetchJSONAuth<T, P extends { parse: (arg: string) => T }>( export async function fetchJSONAuth<T, P extends { parse: (arg: string) => T }>(