diff --git a/ui/src/app/certificate_requests/asideForm.tsx b/ui/src/app/certificate_requests/asideForm.tsx index 078f1c6..2c04105 100644 --- a/ui/src/app/certificate_requests/asideForm.tsx +++ b/ui/src/app/certificate_requests/asideForm.tsx @@ -8,12 +8,17 @@ import { AsideContext } from "../aside"; export default function CertificateRequestsAsidePanel(): JSX.Element { const asideContext = useContext(AsideContext) const [cookies, setCookie, removeCookie] = useCookies(['user_token']); + const [errorText, setErrorText] = useState("") const queryClient = useQueryClient() const mutation = useMutation(postCSR, { onSuccess: () => { + setErrorText("") asideContext.setIsOpen(false) queryClient.invalidateQueries('csrs') }, + onError: (e: Error) => { + setErrorText(e.message) + } }) const [CSRPEMString, setCSRPEMString] = useState("") const handleTextChange = (event: ChangeEvent) => { @@ -53,7 +58,7 @@ export default function CertificateRequestsAsidePanel(): JSX.Element {
- mutation.mutate({ authToken: cookies.user_token, csr: CSRPEMString })} /> + mutation.mutate({ authToken: cookies.user_token, csr: CSRPEMString })} />
@@ -61,18 +66,28 @@ export default function CertificateRequestsAsidePanel(): JSX.Element { ) } -function SubmitCSR({ csrText, onClickFunc }: { csrText: string, onClickFunc: any }) { +function SubmitCSR({ csrText, errorText, onClickFunc }: { csrText: string, errorText: string, onClickFunc: any }) { let csrIsValid = false try { extractCSR(csrText.trim()) csrIsValid = true } catch { } - const validationComponent = csrText == "" ? <> : csrIsValid ?
Valid CSR
:
Invalid CSR
- const buttonComponent = csrIsValid ? : + const buttonComponent = csrIsValid ? ( + + ) : ( + ) return ( <> + {errorText != "" && +
+
+
Error
+

{errorText.split("error: ")}

+
+
+ } {validationComponent} {buttonComponent} diff --git a/ui/src/app/queries.ts b/ui/src/app/queries.ts index 7940ae1..22eadf5 100644 --- a/ui/src/app/queries.ts +++ b/ui/src/app/queries.ts @@ -38,8 +38,9 @@ export async function postCSR(params: { authToken: string, csr: string }) { }, body: params.csr.trim() }) + const responseText = await response.text() if (!response.ok) { - throw new Error(`${response.status}: ${HTTPStatus(response.status)}`) + throw new Error(`${response.status}: ${HTTPStatus(response.status)}. ${responseText}`) } return response.json() }