feat: Convert ts files to js files for errors directory

This commit is contained in:
Faruk AYDIN
2023-12-28 13:14:58 +01:00
parent a2986d70a0
commit 9b01a2a4da
8 changed files with 30 additions and 41 deletions

View File

@@ -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;

View 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!`;
}
}

View File

@@ -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!`;
}
}

View 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;
}
}

View File

@@ -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;
}
}