Merge pull request #1509 from automatisch/errors-folder-js
feat: Convert ts files to js files for errors directory
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class BaseError extends Error {
|
||||
details = {};
|
||||
statusCode?: number;
|
||||
|
||||
constructor(error?: string | IJSONObject) {
|
||||
let computedError: Record<string, unknown>;
|
||||
constructor(error) {
|
||||
let computedError;
|
||||
|
||||
try {
|
||||
computedError = JSON.parse(error as string);
|
||||
computedError = JSON.parse(error);
|
||||
} catch {
|
||||
computedError = (typeof error === 'string' || Array.isArray(error)) ? { error } : error;
|
||||
computedError =
|
||||
typeof error === 'string' || Array.isArray(error) ? { error } : error;
|
||||
}
|
||||
|
||||
let computedMessage: string;
|
||||
let computedMessage;
|
||||
|
||||
try {
|
||||
// challenge to input to see if it is stringified JSON
|
||||
JSON.parse(error as string);
|
||||
computedMessage = error as string;
|
||||
JSON.parse(error);
|
||||
computedMessage = error;
|
||||
} catch {
|
||||
if (typeof error === 'string') {
|
||||
computedMessage = error;
|
10
packages/backend/src/errors/generate-auth-url.js
Normal file
10
packages/backend/src/errors/generate-auth-url.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import BaseError from './base';
|
||||
|
||||
export default class GenerateAuthUrlError extends BaseError {
|
||||
constructor(error) {
|
||||
const computedError = error.response?.data || error.message;
|
||||
super(computedError);
|
||||
|
||||
this.message = `Error occured while creating authorization URL!`;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import BaseError from './base';
|
||||
|
||||
export default class GenerateAuthUrlError extends BaseError {
|
||||
constructor(error: IJSONObject) {
|
||||
const computedError =
|
||||
((error.response as IJSONObject)?.data as IJSONObject) ||
|
||||
(error.message as string);
|
||||
|
||||
super(computedError);
|
||||
|
||||
this.message = `Error occured while creating authorization URL!`;
|
||||
}
|
||||
}
|
10
packages/backend/src/errors/http.js
Normal file
10
packages/backend/src/errors/http.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import BaseError from './base';
|
||||
|
||||
export default class HttpError extends BaseError {
|
||||
constructor(error) {
|
||||
const computedError = error.response?.data || error.message;
|
||||
super(computedError);
|
||||
|
||||
this.response = error.response;
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
import type { AxiosResponse, AxiosError } from 'axios';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import BaseError from './base';
|
||||
|
||||
export default class HttpError extends BaseError {
|
||||
response: AxiosResponse;
|
||||
|
||||
constructor(error: AxiosError) {
|
||||
const computedError =
|
||||
error.response?.data as IJSONObject ||
|
||||
error.message as string;
|
||||
|
||||
super(computedError);
|
||||
|
||||
this.response = error.response;
|
||||
}
|
||||
}
|
@@ -1,15 +1,7 @@
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import logger from './logger';
|
||||
|
||||
import BaseError from '../errors/base';
|
||||
|
||||
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
||||
const errorHandler = (
|
||||
err: BaseError,
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): void => {
|
||||
const errorHandler = (err, req, res, next) => {
|
||||
if (err.message === 'Not Found') {
|
||||
res.status(404).end();
|
||||
} else {
|
@@ -9,13 +9,7 @@ import HttpError from '../errors/http';
|
||||
import EarlyExitError from '../errors/early-exit';
|
||||
import AlreadyProcessedError from '../errors/already-processed';
|
||||
|
||||
type ProcessActionOptions = {
|
||||
flowId: string;
|
||||
executionId: string;
|
||||
stepId: string;
|
||||
};
|
||||
|
||||
export const processAction = async (options: ProcessActionOptions) => {
|
||||
export const processAction = async (options) => {
|
||||
const { flowId, stepId, executionId } = options;
|
||||
|
||||
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
@@ -5,12 +5,7 @@ import AlreadyProcessedError from '../errors/already-processed';
|
||||
import HttpError from '../errors/http';
|
||||
import { logger } from '../helpers/logger';
|
||||
|
||||
type ProcessFlowOptions = {
|
||||
flowId: string;
|
||||
testRun?: boolean;
|
||||
};
|
||||
|
||||
export const processFlow = async (options: ProcessFlowOptions) => {
|
||||
export const processFlow = async (options) => {
|
||||
const { testRun, flowId } = options;
|
||||
const flow = await Flow.query().findById(flowId).throwIfNotFound();
|
||||
const triggerStep = await flow.getTriggerStep();
|
@@ -1,13 +1,9 @@
|
||||
import Step from '../models/step';
|
||||
import { processFlow } from '../services/flow';
|
||||
import { processTrigger } from '../services/trigger';
|
||||
import { processAction } from '../services/action';
|
||||
import { processFlow } from './flow';
|
||||
import { processTrigger } from './trigger';
|
||||
import { processAction } from './action';
|
||||
|
||||
type TestRunOptions = {
|
||||
stepId: string;
|
||||
};
|
||||
|
||||
const testRun = async (options: TestRunOptions) => {
|
||||
const testRun = async (options) => {
|
||||
const untilStep = await Step.query()
|
||||
.findById(options.stepId)
|
||||
.throwIfNotFound();
|
@@ -1,18 +1,9 @@
|
||||
import { IJSONObject, ITriggerItem } from '@automatisch/types';
|
||||
import Step from '../models/step';
|
||||
import Flow from '../models/flow';
|
||||
import Execution from '../models/execution';
|
||||
import globalVariable from '../helpers/global-variable';
|
||||
|
||||
type ProcessTriggerOptions = {
|
||||
flowId: string;
|
||||
stepId: string;
|
||||
triggerItem?: ITriggerItem;
|
||||
error?: IJSONObject;
|
||||
testRun?: boolean;
|
||||
};
|
||||
|
||||
export const processTrigger = async (options: ProcessTriggerOptions) => {
|
||||
export const processTrigger = async (options) => {
|
||||
const { flowId, stepId, triggerItem, error, testRun } = options;
|
||||
|
||||
const step = await Step.query().findById(stepId).throwIfNotFound();
|
Reference in New Issue
Block a user