feat: Introduce http error class
This commit is contained in:
3
packages/backend/src/errors/http-error.ts
Normal file
3
packages/backend/src/errors/http-error.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import BaseError from './base';
|
||||||
|
|
||||||
|
export default class HttpError extends BaseError {}
|
@@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig } from 'axios';
|
|||||||
export { AxiosInstance as IHttpClient } from 'axios';
|
export { AxiosInstance as IHttpClient } from 'axios';
|
||||||
import { IHttpClientParams } from '@automatisch/types';
|
import { IHttpClientParams } from '@automatisch/types';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
|
import HttpError from '../../errors/http-error';
|
||||||
|
|
||||||
const removeBaseUrlForAbsoluteUrls = (
|
const removeBaseUrlForAbsoluteUrls = (
|
||||||
requestConfig: AxiosRequestConfig
|
requestConfig: AxiosRequestConfig
|
||||||
@@ -39,8 +40,7 @@ export default function createHttpClient({
|
|||||||
instance.interceptors.response.use(
|
instance.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
error.response.httpError = error.response.data;
|
throw new HttpError(error.response.data);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import Flow from '../models/flow';
|
import Flow from '../models/flow';
|
||||||
import globalVariable from '../helpers/global-variable';
|
import globalVariable from '../helpers/global-variable';
|
||||||
import EarlyExitError from '../errors/early-exit';
|
import EarlyExitError from '../errors/early-exit';
|
||||||
|
import HttpError from '../errors/http-error';
|
||||||
|
|
||||||
type ProcessFlowOptions = {
|
type ProcessFlowOptions = {
|
||||||
flowId: string;
|
flowId: string;
|
||||||
@@ -25,8 +26,8 @@ export const processFlow = async (options: ProcessFlowOptions) => {
|
|||||||
await triggerCommand.run($);
|
await triggerCommand.run($);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof EarlyExitError === false) {
|
if (error instanceof EarlyExitError === false) {
|
||||||
if (error?.response?.httpError) {
|
if (error instanceof HttpError) {
|
||||||
$.triggerOutput.error = error.response.httpError;
|
$.triggerOutput.error = error.error;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$.triggerOutput.error = JSON.parse(error.message);
|
$.triggerOutput.error = JSON.parse(error.message);
|
||||||
|
Reference in New Issue
Block a user