-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add specific error classes for SDKClient and MirrorNodeCLient (#382)
* add specific error classes for SDKClient and MirrorNodeCLient Signed-off-by: lukelee-sl <[email protected]> * address sonarCloud issue Signed-off-by: lukelee-sl <[email protected]> * fix spacing Signed-off-by: lukelee-sl <[email protected]> * revert spacing change Signed-off-by: lukelee-sl <[email protected]> * refactor to address code review comments Signed-off-by: lukelee-sl <[email protected]> * address sonarCloud issue Signed-off-by: lukelee-sl <[email protected]> * address code review comments Signed-off-by: lukelee-sl <[email protected]> * fix build error Signed-off-by: lukelee-sl <[email protected]>
- Loading branch information
1 parent
acc4c9e
commit 61ae4d4
Showing
12 changed files
with
168 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
export class MirrorNodeClientError extends Error { | ||
public statusCode: number; | ||
|
||
constructor(message: string, statusCode: number) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
|
||
Object.setPrototypeOf(this, MirrorNodeClientError.prototype); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { Status } from "@hashgraph/sdk"; | ||
|
||
export class SDKClientError extends Error { | ||
public status: Status = Status.Unknown; | ||
private validNetworkError: boolean = false; | ||
|
||
constructor(e: any, message?: string) { | ||
super(e && e.status && e.status._code ? e.message : message); | ||
|
||
if(e && e.status && e.status._code) { | ||
this.validNetworkError = true; | ||
this.status = e.status; | ||
} | ||
|
||
Object.setPrototypeOf(this, SDKClientError.prototype); | ||
} | ||
|
||
get statusCode(): number { | ||
return this.status._code; | ||
} | ||
|
||
public isValidNetworkError(): boolean { | ||
return this.validNetworkError; | ||
} | ||
|
||
public isInvalidAccountId(): boolean { | ||
return this.isValidNetworkError() && this.statusCode === Status.InvalidAccountId._code; | ||
} | ||
|
||
public isInvalidContractId(): boolean { | ||
return this.isValidNetworkError() && | ||
(this.statusCode === Status.InvalidContractId._code || this.message?.includes(Status.InvalidContractId.toString())); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.