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 {
|
export default class BaseError extends Error {
|
||||||
details = {};
|
details = {};
|
||||||
statusCode?: number;
|
|
||||||
|
|
||||||
constructor(error?: string | IJSONObject) {
|
constructor(error) {
|
||||||
let computedError: Record<string, unknown>;
|
let computedError;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
computedError = JSON.parse(error as string);
|
computedError = JSON.parse(error);
|
||||||
} catch {
|
} 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 {
|
try {
|
||||||
// challenge to input to see if it is stringified JSON
|
// challenge to input to see if it is stringified JSON
|
||||||
JSON.parse(error as string);
|
JSON.parse(error);
|
||||||
computedMessage = error as string;
|
computedMessage = error;
|
||||||
} catch {
|
} catch {
|
||||||
if (typeof error === 'string') {
|
if (typeof error === 'string') {
|
||||||
computedMessage = error;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user