@@ -7,6 +7,7 @@ import type {
77 AxiosResponseHeaders ,
88 RawAxiosResponseHeaders ,
99} from "axios" ;
10+ import { log } from "./logger" ;
1011
1112// Dynamic EventSource import for cross-platform compatibility
1213let EventSource : any ;
@@ -22,7 +23,7 @@ function initializeEventSource() {
2223 // Use require for Node.js environments
2324 EventSource = require ( "eventsource" ) ;
2425 } catch ( error ) {
25- console . warn (
26+ log . error (
2627 "eventsource package not available, EventSource functionality may not work in Node.js environment" ,
2728 ) ;
2829 EventSource = null ;
@@ -51,6 +52,7 @@ class VerityRequest<T> {
5152 private axiosInstance : AxiosInstance ;
5253 private redacted : string | null = null ;
5354 public requestId : string ;
55+ public strictProof = false ;
5456 private url : string ;
5557 private sse_is_ready = false ;
5658 private proof : Promise < string > ;
@@ -60,18 +62,20 @@ class VerityRequest<T> {
6062 method : string ,
6163 Url : string ,
6264 config ?: AxiosRequestConfig ,
65+ strictProof ?: boolean ,
6366 data ?: any ,
6467 ) {
6568 const { url, ...rest } = config ?? { } ;
6669 this . config = rest || { } ;
6770 this . requestId = uuidv4 ( ) . toString ( ) ;
6871 this . url = Url ;
72+ this . strictProof = strictProof || false ;
6973
7074 this . axiosInstance = axiosInstance ;
7175 this . proof = this . subscribeToProof ( ) . catch ( ( err ) => {
72- console . error ( `Proof SSE failed for ${ this . requestId } :` , err ) ;
76+ log . error ( `Proof SSE failed for ${ this . requestId } :` , err ) ;
7377 // re-throw so downstream still sees the error
74- throw err ;
78+ return strictProof ? Promise . reject ( err ) : "" ;
7579 } ) ;
7680
7781 const instance = axios . create ( ) ;
@@ -90,7 +94,7 @@ class VerityRequest<T> {
9094 response . proof = data . slice ( index + 1 ) ;
9195 return response ;
9296 } catch ( error ) {
93- console . log ( { error } ) ;
97+ log . error ( { error } ) ;
9498 return response ;
9599 }
96100 } ,
@@ -183,9 +187,9 @@ class VerityRequest<T> {
183187
184188 es . onerror = ( err : any ) => {
185189 clearTimeout ( timeout ) ;
186- console . error ( "SSE error:" , err ) ;
190+ log . error ( "SSE error:" , err ) ;
187191 es . close ( ) ;
188- reject ( err ) ;
192+ this . strictProof ? reject ( err ) : resolve ( "" ) ;
189193 } ;
190194 } ) ;
191195 }
@@ -204,14 +208,25 @@ export class VerityClient {
204208 } ) ;
205209 }
206210
207- get < T > ( url : string , config ?: AxiosRequestConfig ) {
208- return new VerityRequest < T > ( this . axios , "get" , url , config ) ;
211+ get < T > ( url : string , config ?: AxiosRequestConfig , strictProof = false ) {
212+ return new VerityRequest < T > ( this . axios , "get" , url , config , strictProof ) ;
209213 }
210214
211- post < T > ( url : string , config ?: AxiosRequestConfig , data ?: any ) {
212- return new VerityRequest < T > ( this . axios , "post" , url , config , data ) ;
215+ post < T > (
216+ url : string ,
217+ config ?: AxiosRequestConfig ,
218+ data ?: any ,
219+ strictProof = false ,
220+ ) {
221+ return new VerityRequest < T > (
222+ this . axios ,
223+ "post" ,
224+ url ,
225+ config ,
226+ strictProof ,
227+ data ,
228+ ) ;
213229 }
214-
215230 /// Get the information of the connected notary
216231 async get_notary_info ( ) {
217232 const response = await this . axios . get < INotaryInformation > ( "/notaryinfo" ) ;
0 commit comments