1- import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes" ;
2- import { createResultObject } from "src/dataMappings/utils/createResultObject" ;
3- import { MAX_BYTE_SIZE } from "src/consts" ;
1+ import { MAX_BYTE_SIZE } from "../../consts" ;
2+ import { RequestError } from "../../errors" ;
3+ import { FetchIpfsJsonMapping } from "../utils/actionTypes" ;
4+ import { createResultObject } from "../utils/createResultObject" ;
45
56export const fetchIpfsJsonAction = async ( mapping : FetchIpfsJsonMapping ) => {
67 const { ipfsUri, seek, populate } = mapping ;
@@ -13,26 +14,26 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
1314 } else if ( ! ipfsUri . startsWith ( "http" ) ) {
1415 httpUri = `https://ipfs.io/ipfs/${ ipfsUri } ` ;
1516 } else {
16- throw new Error ( "Invalid IPFS URI format" ) ;
17+ throw new RequestError ( "Invalid IPFS URI format" , httpUri ) ;
1718 }
1819
1920 const response = await fetch ( httpUri , { method : "GET" } ) ;
2021
2122 if ( ! response . ok ) {
22- throw new Error ( "Failed to fetch data from IPFS" ) ;
23+ throw new RequestError ( "Failed to fetch data from IPFS" , httpUri ) ;
2324 }
2425
2526 const contentLength = response . headers . get ( "content-length" ) ;
2627 if ( contentLength && parseInt ( contentLength ) > MAX_BYTE_SIZE ) {
27- throw new Error ( "Response size is too large" ) ;
28+ throw new RequestError ( "Response size is too large" , httpUri ) ;
2829 }
2930
3031 const contentType = response . headers . get ( "content-type" ) ;
3132 if ( ! contentType || ! contentType . includes ( "application/json" ) ) {
32- throw new Error ( "Fetched data is not JSON" ) ;
33+ throw new RequestError ( "Fetched data is not JSON" , httpUri ) ;
3334 }
3435
35- const data = await response . json ( ) ;
36+ const data = ( await response . json ( ) ) as any ;
3637
3738 return createResultObject ( data , seek , populate ) ;
3839} ;
0 commit comments