mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Handle webhook request errors correctly (#18080)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { defineOperationApi, isValidJSON } from '@directus/utils';
|
||||
import encodeUrl from 'encodeurl';
|
||||
import { getAxios } from '../../request/index.js';
|
||||
import { isAxiosError } from 'axios';
|
||||
|
||||
type Options = {
|
||||
url: string;
|
||||
@@ -34,13 +35,17 @@ export default defineOperationApi<Options>({
|
||||
});
|
||||
|
||||
return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
|
||||
} catch (error: any) {
|
||||
throw JSON.stringify({
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText,
|
||||
headers: error.response.headers,
|
||||
data: error.response.data,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
if (isAxiosError(error)) {
|
||||
throw JSON.stringify({
|
||||
status: error.response?.status,
|
||||
statusText: error.response?.statusText,
|
||||
headers: error.response?.headers,
|
||||
data: error.response?.data,
|
||||
});
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user