Skip to content

Commit

Permalink
refactor: added new error category class httpError
Browse files Browse the repository at this point in the history
  • Loading branch information
hui-an-yang committed Jan 16, 2023
1 parent 641838f commit 9d8da62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/taquito-core/src/error/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PermissionDeniedError,
UnsupportedAction,
InternalValidationError,
HttpError,
} from './errors';
import { STATUS_CODE } from '../constants/http_status_code';

Expand Down Expand Up @@ -195,7 +196,7 @@ export class ProhibitedActionError extends PermissionDeniedError {
* @param body Http request body
* @param url http request url
*/
export class HttpResponseError extends Error {
export class HttpResponseError extends HttpError {
public name = 'HttpResponse';

constructor(
Expand Down
16 changes: 14 additions & 2 deletions packages/taquito-core/src/error/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @category Error
* @description Error that indicates the data get from other servies has incorrect format
* @description Error that indicates invalid data being fetched from other services
*/
export class InternalValidationError extends Error {
public name = 'InternalValidationError';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class NetworkError extends Error {

/**
* @category Error
* @description Error that indicates
* @description Error that permission deneied for a certain action
*/
export class PermissionDeniedError extends Error {
public name = 'PermissionDeniedError';
Expand All @@ -80,3 +80,15 @@ export class PermissionDeniedError extends Error {
super(message);
}
}

/**
* @category Error
* @description Error with Http services
*/
export class HttpError extends Error {
public name = 'HttpError';
public category = this.name;
constructor(public message: string) {
super(message);
}
}
4 changes: 2 additions & 2 deletions packages/taquito-http-utils/src/taquito-http-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { STATUS_CODE } from '@taquito/core';
import axios, { AxiosAdapter } from 'axios';
import { HttpResponseError, ParameterValidationError } from '@taquito/core';
import { HttpResponseError, HttpError } from '@taquito/core';

const isNode =
typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface HttpRequestOptions {
* @category Error
* @description Error that indicates a general failure in making the HTTP request
*/
export class HttpRequestFailed extends ParameterValidationError {
export class HttpRequestFailed extends HttpError {
public name = 'HttpRequestFailed';

constructor(public message: string) {
Expand Down

0 comments on commit 9d8da62

Please sign in to comment.