Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broken request error handling #1676

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions web-app/src/common/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ export class API {

onError(err: any) {
if (err.status) {
const errMessage = get(
err.response,
"body.message",
`Error ${err.status.toString()}`
);
const errMessage =
get(err.response, "body.message", `Error ${err.status.toString()}`) ||
"";

let detailedMessage = get(err.response, "body.detailedMessage", "");
let detailedMessage = get(err.response, "body.detailedMessage", "") || "";

if (errMessage === detailedMessage) {
detailedMessage = "";
Expand Down
1 change: 1 addition & 0 deletions web-app/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface ErrorResponseHandler {
errorMessage: string;
detailedError: string;
statusCode?: number;
message?: string; // if any type error thrown
}

export interface IBytesCalc {
Expand Down
50 changes: 35 additions & 15 deletions web-app/src/screens/Console/Tenants/TenantDetails/TenantYAML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,24 @@ const TenantYAML = ({ classes }: ITenantYAMLProps) => {
})
.catch((err: ErrorResponseHandler) => {
setAddLoading(false);
setErrorMessage(err.errorMessage);
const errMessage = err?.message || "" || err.errorMessage;
setErrorMessage(errMessage);
});
};

useEffect(() => {
api
.invoke("GET", `/api/v1/namespaces/${namespace}/tenants/${tenant}/yaml`)
.then((res: ITenantYAML) => {
setLoading(false);
setTenantYaml(res.yaml);
})
.catch((err: ErrorResponseHandler) => {
setLoading(false);
dispatch(setModalErrorSnackMessage(err));
});
if (namespace && tenant) {
api
.invoke("GET", `/api/v1/namespaces/${namespace}/tenants/${tenant}/yaml`)
.then((res: ITenantYAML) => {
setLoading(false);
setTenantYaml(res.yaml);
})
.catch((err: ErrorResponseHandler) => {
setLoading(false);
dispatch(setModalErrorSnackMessage(err));
});
}
}, [tenant, namespace, dispatch]);

useEffect(() => {}, []);
Expand All @@ -116,23 +119,40 @@ const TenantYAML = ({ classes }: ITenantYAMLProps) => {
<LinearProgress />
</Grid>
))}
{errorMessage !== "" && (
<div className={classes.errorState}>{errorMessage}</div>
)}

{!loading && (
<form
noValidate
autoComplete="off"
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
updateTenant(e);
}}
>
<Grid container>
<Grid item xs={12}>
<SectionTitle>Tenant Specification</SectionTitle>
</Grid>
<Grid item xs={12}>
{errorMessage ? (
<Grid
item
xs={12}
sx={{
marginTop: "5px",
marginBottom: "2px",
border: "1px solid #b53b4b",
borderRadius: "2px",
padding: "5px",
}}
>
<div className={classes.errorState}>{errorMessage}</div>
</Grid>
) : null}
<Grid
item
xs={12}
sx={errorMessage ? { border: "1px solid #b53b4b" } : {}}
>
<CodeMirrorWrapper
value={tenantYaml}
mode={"yaml"}
Expand Down