https://github.com/latticesurgery-com/web-ui/blob/de846b41fe89590d438658b25d203a4be209a485/src/apiResponses.ts
Has several very similar error classes. Maybe we could unify the behavior with an interface like:
interface ResponseError
{
title : string
msg : string
}
This way we can remove the 4 cases:
|
{appState.apiResponse instanceof ApiHttpError && ( |
|
<Alert w={{ base: "100%", sm: "80%", md: "65%" }} mx={"auto"} status="error"> |
|
<AlertIcon /> |
|
<AlertTitle mr={2}>{"API Status: " + appState.apiResponse.code}</AlertTitle> |
|
<AlertDescription>{appState.apiResponse.msg}</AlertDescription> |
|
</Alert> |
|
)} |
|
|
|
{appState.apiResponse instanceof CompilerError && ( |
|
<Alert w={{ base: "100%", sm: "80%", md: "65%" }} mx={"auto"} status="error"> |
|
<AlertIcon /> |
|
<AlertTitle mr={2}>Compiler Error!</AlertTitle> |
|
<AlertDescription>{`${appState.apiResponse.msg}: ${appState.apiResponse.errortype}`}</AlertDescription> |
|
</Alert> |
|
)} |
|
|
|
{appState.apiResponse instanceof JsonParseError && ( |
|
<Alert w={{ base: "100%", sm: "80%", md: "65%" }} mx={"auto"} status="error"> |
|
<AlertIcon /> |
|
<AlertTitle mr={2}>Failed to process results!</AlertTitle> |
|
<AlertDescription>{appState.apiResponse.msg}</AlertDescription> |
|
</Alert> |
|
)} |
|
|
|
{appState.apiResponse instanceof NoServerResponse && ( |
|
<Alert w={{ base: "100%", sm: "80%", md: "65%" }} mx={"auto"} status="error"> |
|
<AlertIcon /> |
|
<AlertTitle mr={2}>Server failed to respond!</AlertTitle> |
|
<AlertDescription>{appState.apiResponse.response}</AlertDescription> |
|
</Alert> |
|
)} |
with:
{appState.apiResponse instanceof ResponseError && (
<Alert w={{ base: "100%", sm: "80%", md: "65%" }} mx={"auto"} status="error">
<AlertIcon />
<AlertTitle mr={2}>{appState.apiResponse.title}</AlertTitle>
<AlertDescription>{appState.apiResponse.msg}</AlertDescription>
</Alert>
)}