Improve error handling for Fetch calls (#24460)

Closes #24293
This commit is contained in:
Jon Koops 2023-11-01 12:47:23 +01:00 committed by GitHub
parent 17135a0cff
commit b0c22ce357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 7 deletions

View file

@ -1,3 +1,4 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import type AuthenticationFlowRepresentation from "@keycloak/keycloak-admin-client/lib/defs/authenticationFlowRepresentation";
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import {
@ -101,7 +102,7 @@ export default function AuthenticationSection() {
]);
const loader = async () => {
const flowsRequest = await fetch(
const flowsRequest = await fetchWithError(
`${addTrailingSlash(
adminClient.baseUrl,
)}admin/realms/${realmName}/ui-ext/authentication-management/flows`,

View file

@ -1,3 +1,4 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
import { Language } from "@patternfly/react-code-editor";
import {
@ -61,7 +62,7 @@ export default function ImportForm() {
return JSON.parse(contents);
}
const response = await fetch(
const response = await fetchWithError(
`${addTrailingSlash(
adminClient.baseUrl,
)}admin/realms/${realm}/client-description-converter`,

View file

@ -1,3 +1,4 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import {
Form,
FormGroup,
@ -11,8 +12,8 @@ import {
import { saveAs } from "file-saver";
import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { HelpItem, useHelp } from "ui-shared";
import { adminClient } from "../../admin-client";
import { useRealm } from "../../context/realm-context/RealmContext";
import { useServerInfo } from "../../context/server-info/ServerInfoProvider";
@ -61,7 +62,7 @@ export const DownloadDialog = ({
useFetch(
async () => {
if (selectedConfig?.mediaType === "application/zip") {
const response = await fetch(
const response = await fetchWithError(
`${addTrailingSlash(
adminClient.baseUrl,
)}admin/realms/${realm}/clients/${id}/installation/providers/${selected}`,

View file

@ -1,3 +1,4 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import { adminClient } from "../../admin-client";
import { getAuthorizationHeaders } from "../../utils/getAuthorizationHeaders";
import { joinPath } from "../../utils/joinPath";
@ -9,7 +10,7 @@ export async function fetchAdminUI<T>(
const accessToken = await adminClient.getAccessToken();
const baseUrl = adminClient.baseUrl;
const response = await fetch(
const response = await fetchWithError(
joinPath(baseUrl, "admin/realms", adminClient.realmName, endpoint) +
(query ? "?" + new URLSearchParams(query) : ""),
{

View file

@ -1,3 +1,4 @@
import { fetchWithError } from "@keycloak/keycloak-admin-client";
import type IdentityProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderRepresentation";
import { FormGroup, Title } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
@ -47,7 +48,7 @@ export const SamlConnectSettings = () => {
formData.append("file", new Blob([xml]));
try {
const response = await fetch(
const response = await fetchWithError(
`${addTrailingSlash(
adminClient.baseUrl,
)}admin/realms/${realm}/identity-provider/import-config`,

View file

@ -3,5 +3,5 @@ import { RequiredActionAlias } from "./defs/requiredActionProviderRepresentation
export const requiredAction = RequiredActionAlias;
export default KeycloakAdminClient;
export { NetworkError } from "./utils/fetchWithError.js";
export { NetworkError, fetchWithError } from "./utils/fetchWithError.js";
export type { NetworkErrorOptions } from "./utils/fetchWithError.js";