aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/http/common.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-27 20:57:41 +0800
committercrupest <crupest@outlook.com>2022-04-27 20:57:41 +0800
commita4f5080c6dc8c3fc7f76aebb13cbf54c0ed7ef15 (patch)
tree067f053e57260dd3f876590dcbc7802721eaac50 /FrontEnd/src/http/common.ts
parent6c10782e909427a8e6ddd56d1d081d19346b9688 (diff)
downloadtimeline-a4f5080c6dc8c3fc7f76aebb13cbf54c0ed7ef15.tar.gz
timeline-a4f5080c6dc8c3fc7f76aebb13cbf54c0ed7ef15.tar.bz2
timeline-a4f5080c6dc8c3fc7f76aebb13cbf54c0ed7ef15.zip
...
Diffstat (limited to 'FrontEnd/src/http/common.ts')
-rw-r--r--FrontEnd/src/http/common.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/FrontEnd/src/http/common.ts b/FrontEnd/src/http/common.ts
index 25c69012..b7d579c7 100644
--- a/FrontEnd/src/http/common.ts
+++ b/FrontEnd/src/http/common.ts
@@ -27,6 +27,12 @@ export class HttpNotFoundError extends Error {
}
}
+export class HttpBadRequestError extends Error {
+ constructor(public innerError?: AxiosError) {
+ super();
+ }
+}
+
function convertNetworkError(error: AxiosError): never {
if (error.isAxiosError && error.response == null) {
throw new HttpNetworkError(error);
@@ -56,10 +62,20 @@ function convertNotFoundError(error: AxiosError): never {
}
}
+function convertBadRequestError(error: AxiosError): never {
+ const statusCode = error.response?.status;
+ if (statusCode === 422) {
+ throw new HttpBadRequestError(error);
+ } else {
+ throw error;
+ }
+}
+
export function configureAxios(axios: Axios): void {
axios.interceptors.response.use(identity, convertNetworkError);
axios.interceptors.response.use(identity, convertForbiddenError);
axios.interceptors.response.use(identity, convertNotFoundError);
+ axios.interceptors.response.use(identity, convertBadRequestError);
}
configureAxios(axios);