Skip to content

Commit

Permalink
updates error handling to their new API response 400 object (#5069)
Browse files Browse the repository at this point in the history
* updates error handling to their new API response 400 object

* removing old error type
  • Loading branch information
patnir authored Jun 24, 2024
1 parent 66e195d commit 0ac6ce8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 8 additions & 7 deletions ironfish-cli/src/utils/chainport/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import axios from 'axios'
import { getConfig } from './config'
import {
ChainportBridgeTransaction,
ChainportError,
ChainportNetwork,
ChainportTransactionStatus,
ChainportVerifiedToken,
Expand Down Expand Up @@ -61,16 +60,18 @@ export const fetchChainportBridgeTransaction = async (

const makeChainportRequest = async <T extends object>(url: string): Promise<T> => {
const response = await axios
.get<T | ChainportError>(url)
.get<T>(url)
.then((response) => {
if ('Error' in response.data) {
throw new Error(response.data.Error)
}

return response.data
})
.catch((error) => {
throw new Error('Chainport error: ' + error)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const chainportError = error.response?.data?.error?.description as string
if (chainportError) {
throw new Error(chainportError)
} else {
throw new Error('Chainport error - ' + error)
}
})

return response
Expand Down
4 changes: 0 additions & 4 deletions ironfish-cli/src/utils/chainport/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@ export type ChainportTransactionStatus =
created_at: string | null
port_in_ack: boolean | null
}

export type ChainportError = {
Error: string
}

0 comments on commit 0ac6ce8

Please sign in to comment.