@@ -4,6 +4,7 @@ import type { ThirdwebClient } from "../client/client.js";
44import { getThirdwebBaseUrl } from "../utils/domains.js" ;
55import { getClientFetch } from "../utils/fetch.js" ;
66import { stringify } from "../utils/json.js" ;
7+ import { BridgeApiError } from "./types/Errors.js" ;
78import type { PreparedQuote , Quote } from "./types/Quote.js" ;
89
910/**
@@ -127,9 +128,12 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
127128 const response = await clientFetch ( url . toString ( ) ) ;
128129 if ( ! response . ok ) {
129130 const errorJson = await response . json ( ) ;
130- throw new Error (
131- `${ errorJson . code } | ${ errorJson . message } - ${ errorJson . correlationId } ` ,
132- ) ;
131+ throw new BridgeApiError ( {
132+ code : errorJson . code || "UNKNOWN_ERROR" ,
133+ message : errorJson . message || response . statusText ,
134+ correlationId : errorJson . correlationId || undefined ,
135+ statusCode : response . status ,
136+ } ) ;
133137 }
134138
135139 const { data } : { data : Quote } = await response . json ( ) ;
@@ -357,9 +361,12 @@ export async function prepare(
357361 } ) ;
358362 if ( ! response . ok ) {
359363 const errorJson = await response . json ( ) ;
360- throw new Error (
361- `${ errorJson . code } | ${ errorJson . message } - ${ errorJson . correlationId } ` ,
362- ) ;
364+ throw new BridgeApiError ( {
365+ code : errorJson . code || "UNKNOWN_ERROR" ,
366+ message : errorJson . message || response . statusText ,
367+ correlationId : errorJson . correlationId || undefined ,
368+ statusCode : response . status ,
369+ } ) ;
363370 }
364371
365372 const { data } : { data : PreparedQuote } = await response . json ( ) ;
0 commit comments