Skip to content

Commit

Permalink
refactor: error imporvement of http-utils package and updated high ca…
Browse files Browse the repository at this point in the history
…tegory error format

re #1994
  • Loading branch information
hui-an-yang committed Jan 13, 2023
1 parent 106bec7 commit e708166
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 603 deletions.
2 changes: 1 addition & 1 deletion integration-tests/rpc-taquito.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CONFIGS } from "./config";
import { RpcClient } from '@taquito/rpc';
import { HttpResponseError } from "@taquito/http-utils";
import { HttpResponseError } from "@taquito/core";


CONFIGS().forEach(({ rpc, knownContract }) => {
Expand Down
28 changes: 24 additions & 4 deletions packages/taquito-core/src/error/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
ParameterValidationError,
PermissionDeniedError,
UnsupportedAction,
ValidationError,
InternalValidationError,
} from './errors';
import { STATUS_CODE } from '../interface/status_code';

/**
* @category Error
Expand Down Expand Up @@ -70,7 +71,7 @@ export class InvalidContractAddressError extends ParameterValidationError {
* @category Error
* @description Error that indicates an invalid block hash being passed or used
*/
export class InvalidBlockHashError extends ValidationError {
export class InvalidBlockHashError extends InternalValidationError {
public name = 'InvalidBlockHashError';
constructor(public blockHash: string) {
super(`The block hash '${blockHash}' is invalid`);
Expand Down Expand Up @@ -122,7 +123,7 @@ export class InvalidPublicKeyError extends ParameterValidationError {
* @category Error
* @description Error that indicates an invalid chain id being passed or used
*/
export class InvalidChainIdError extends ValidationError {
export class InvalidChainIdError extends InternalValidationError {
public name = 'InvalidChainIdError';
constructor(public chainId: string) {
super(`The chain id '${chainId}' is invalid`);
Expand All @@ -144,7 +145,7 @@ export class InvalidKeyHashError extends ParameterValidationError {
* @category Error
* @description Error that indicates an invalid operation hash being passed or used
*/
export class InvalidOperationHashError extends ValidationError {
export class InvalidOperationHashError extends InternalValidationError {
public name = 'InvalidOperationHashError';
constructor(public operationHash: string) {
super(`The operation hash '${operationHash}' is invalid`);
Expand Down Expand Up @@ -183,3 +184,22 @@ export class ProhibitedActionError extends PermissionDeniedError {
super(message);
}
}

// Unsure the need to extend from high category ReponseError where there will only this error as child
/**
* @category Error
* @description This error will be thrown when the endpoint returns an HTTP error to the client
*/
export class HttpResponseError extends Error {
public name = 'HttpResponse';

constructor(
public message: string,
public status: STATUS_CODE,
public statusText: string,
public body: string,
public url: string
) {
super(message);
}
}
23 changes: 9 additions & 14 deletions packages/taquito-core/src/error/errors.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
/**
* @category Error
* @description Error that indicates an invalid user data input
*/
export class ExternalError extends Error {
public name = 'ExternalError';
constructor(public message: string) {
super(message);
}
}

/**
* @category Error
* @description Error that indicates an invalid user data input
* @description Error that indicates the data get from third party has incorrect format
*/
export class ValidationError extends Error {
public name = 'ValidationError';
export class InternalValidationError extends Error {
public name = 'InternalValidationError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand All @@ -26,6 +16,7 @@ export class ValidationError extends Error {
*/
export class ParameterValidationError extends Error {
public name = 'ParameterValidationError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand All @@ -37,6 +28,7 @@ export class ParameterValidationError extends Error {
*/
export class RpcError extends Error {
public name = 'RpcError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand All @@ -48,6 +40,7 @@ export class RpcError extends Error {
*/
export class TezosToolkitConfigError extends Error {
public name = 'TezosToolkitConfigError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand All @@ -70,6 +63,7 @@ export class UnsupportedAction extends Error {
*/
export class NetworkError extends Error {
public name = 'NetworkError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand All @@ -81,6 +75,7 @@ export class NetworkError extends Error {
*/
export class PermissionDeniedError extends Error {
public name = 'PermissionDeniedError';
public category = this.name;
constructor(public message: string) {
super(message);
}
Expand Down
Loading

0 comments on commit e708166

Please sign in to comment.