1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/AlertError.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-05-24 12:49:59 +00:00
import React, { useMemo } from "react"
import Alert from "../base/Alert"
2021-05-25 15:10:40 +00:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
2021-05-24 12:49:59 +00:00
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons"
import {
DecodeError,
ResultError,
SerializationError,
ServerNotConfiguredError,
ViewNotAllowedError,
} from "../../objects/Errors"
import useStrings from "../../hooks/useStrings"
export default function AlertError({ error, ...props }) {
const strings = useStrings()
const content = useMemo(
() => {
if(error instanceof ViewNotAllowedError) {
return strings.errorViewNotAllowed
}
else if(error instanceof ServerNotConfiguredError) {
return strings.errorServerNotConfigured
}
else if(error instanceof DecodeError) {
return strings.errorDecodeError
}
else if(error instanceof ResultError) {
return strings[error.getCode()]
}
else if(error instanceof SerializationError) {
return strings.errorSerializationError
}
else {
return error.toString()
}
},
[strings, error]
)
return (
<Alert color={"Red"} {...props}>
<FontAwesomeIcon icon={faExclamationTriangle}/> {content}
</Alert>
)
}