@@ -11,13 +11,15 @@ interface ResolveOptions {
1111 ipnsGateways ?: string [ ] ;
1212 defaultProtocolIfUnspecified ?: "ipfs" | "ipns" ;
1313 fetchOverride ?: FetchType ;
14+ logErrors ?: boolean ;
1415}
1516
1617const defaultResolveOptions : Required < ResolveOptions > = {
1718 ipfsGateways : defaultIpfsGateways ,
1819 ipnsGateways : defaultIpnsGateways ,
1920 defaultProtocolIfUnspecified : "ipfs" ,
20- fetchOverride : globalThis ?. fetch
21+ fetchOverride : globalThis ?. fetch ,
22+ logErrors : false ,
2123}
2224
2325interface ResolveOutput {
@@ -168,7 +170,7 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
168170
169171 // check the response because a lot of gateways will do redirects and other checks which will not be compatible
170172 // with this library
171- if ( response . status >= 300 || response . status < 200 ) {
173+ if ( response . status >= 300 || response . status < 200 ) {
172174 throw new Error ( `Url (${ urlResolvedFrom } ) did not return a 2xx response` ) ;
173175 }
174176
@@ -177,7 +179,9 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
177179 urlResolvedFrom
178180 }
179181 } catch ( err ) {
180- console . error ( gatewayUrl , err ) ;
182+ if ( _options . logErrors ) {
183+ console . error ( gatewayUrl , err ) ;
184+ }
181185 throw err ;
182186 }
183187 } )
@@ -188,7 +192,13 @@ async function resolve(uri: string, options?: ResolveOptions): Promise<ResolveOu
188192 // abort all the other requests
189193 for ( const abortController of abortControllers ) {
190194 if ( abortController ) {
191- abortController . abort ( )
195+ try {
196+ abortController . abort ( )
197+ } catch ( err ) {
198+ if ( _options . logErrors ) {
199+ throw err ;
200+ }
201+ }
192202 }
193203 }
194204
0 commit comments