Skip to content

Commit

Permalink
more http status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Jul 22, 2024
1 parent 823576a commit af5d390
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function LoginPage() {
{errorText &&
<div className="p-notification--negative">
<div className="p-notification__content">
<h5 className="p-notification__title">Error Logging In</h5>
<h5 className="p-notification__title">Error</h5>
<p className="p-notification__message">{errorText.split("error: ")}</p>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions ui/src/app/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getCertificateRequests(params: { authToken: string }): Pro
headers: { "Authorization": "Bearer " + params.authToken }
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -31,7 +31,7 @@ export async function postCSR(params: { authToken: string, csr: string }) {
body: params.csr.trim()
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -49,7 +49,7 @@ export async function postCertToID(params: RequiredParams) {
body: params.cert.trim()
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -62,7 +62,7 @@ export async function deleteCSR(params: RequiredParams) {
}
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -75,7 +75,7 @@ export async function rejectCSR(params: RequiredParams) {
}
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -88,7 +88,7 @@ export async function revokeCertificate(params: RequiredParams) {
}
})
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}`)
}
return response.json()
}
Expand All @@ -100,7 +100,7 @@ export async function login(userForm: { username: string, password: string }) {
})
const responseText = await response.text()
if (!response.ok) {
throw new Error(`${response.status} ${HTTPStatus(response.status)}. ${responseText}`)
throw new Error(`${response.status}: ${HTTPStatus(response.status)}. ${responseText}`)
}
return responseText
}
4 changes: 4 additions & 0 deletions ui/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ export const csrMatchesCertificate = (csrPemString: string, certPemString: strin

export const HTTPStatus = (code: number): string => {
const map: { [key: number]: string } = {
400: "Bad Request",
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
500: "Internal Server Error",
}
if (!(code in map)) {
throw new Error("code not recognized: " + code)
Expand Down

0 comments on commit af5d390

Please sign in to comment.