@hexar/biometric-identity-sdk-core 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -329,9 +329,19 @@ class BiometricIdentitySDK {
329
329
  logger_1.logger.error('Backend validation failed', {
330
330
  errorMessage: error?.message,
331
331
  errorName: error?.name,
332
- errorStack: error?.stack
332
+ status: error?.status,
333
+ statusText: error?.statusText,
334
+ errorData: error?.errorData,
335
+ errorStack: error?.stack?.substring(0, 500)
336
+ });
337
+ const errorMessage = error?.message ||
338
+ (error?.status ? `Backend request failed with status ${error.status}` : 'Backend validation failed');
339
+ throw this.createError(types_1.BiometricErrorCode.NETWORK_ERROR, errorMessage, {
340
+ status: error?.status,
341
+ statusText: error?.statusText,
342
+ errorData: error?.errorData,
343
+ originalError: error?.message
333
344
  });
334
- throw this.createError(types_1.BiometricErrorCode.NETWORK_ERROR, error?.message || 'Backend validation failed', error);
335
345
  }
336
346
  }
337
347
  /**
@@ -184,6 +184,12 @@ class BackendClient {
184
184
  */
185
185
  async request(endpoint, method, body) {
186
186
  const url = `${this.config.apiEndpoint}${endpoint}`;
187
+ logger_1.logger.info('Making backend request', {
188
+ url,
189
+ method,
190
+ hasBody: !!body,
191
+ bodySize: body ? JSON.stringify(body).length : 0
192
+ });
187
193
  const controller = new AbortController();
188
194
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
189
195
  const headers = {
@@ -200,33 +206,51 @@ class BackendClient {
200
206
  body: body ? JSON.stringify(body) : undefined,
201
207
  signal: controller.signal,
202
208
  });
209
+ logger_1.logger.info('Backend response received', {
210
+ url,
211
+ status: response.status,
212
+ statusText: response.statusText,
213
+ ok: response.ok
214
+ });
203
215
  clearTimeout(timeoutId);
204
216
  if (!response.ok) {
217
+ let errorText = '';
205
218
  let errorData = {};
206
219
  try {
207
- const text = await response.text();
208
- if (text) {
209
- errorData = JSON.parse(text);
220
+ errorText = await response.text();
221
+ if (errorText) {
222
+ try {
223
+ errorData = JSON.parse(errorText);
224
+ }
225
+ catch {
226
+ errorData = { raw: errorText };
227
+ }
210
228
  }
211
229
  }
212
- catch {
213
- errorData = {};
230
+ catch (parseError) {
231
+ logger_1.logger.warn('Could not parse error response', parseError);
214
232
  }
215
233
  const errorMessage = errorData?.error?.message ||
216
234
  errorData?.detail ||
217
235
  errorData?.message ||
218
- `Request failed with status ${response.status}`;
236
+ errorData?.raw ||
237
+ `Request failed with status ${response.status}: ${response.statusText}`;
219
238
  logger_1.logger.error('Backend request failed', {
220
239
  url,
221
240
  method,
222
241
  status: response.status,
223
242
  statusText: response.statusText,
224
- errorData
243
+ errorText: errorText.substring(0, 500),
244
+ errorData: JSON.stringify(errorData).substring(0, 500)
225
245
  });
246
+ const error = new Error(errorMessage);
247
+ error.status = response.status;
248
+ error.statusText = response.statusText;
249
+ error.errorData = errorData;
226
250
  if (response.status === 413) {
227
251
  throw new Error(`Payload too large (413). The request body exceeds the server's size limit. Try reducing the number of video frames or image sizes.`);
228
252
  }
229
- throw new Error(errorMessage);
253
+ throw error;
230
254
  }
231
255
  return await response.json();
232
256
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexar/biometric-identity-sdk-core",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Core AI engine for biometric identity verification",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -414,12 +414,24 @@ export class BiometricIdentitySDK {
414
414
  logger.error('Backend validation failed', {
415
415
  errorMessage: error?.message,
416
416
  errorName: error?.name,
417
- errorStack: error?.stack
417
+ status: error?.status,
418
+ statusText: error?.statusText,
419
+ errorData: error?.errorData,
420
+ errorStack: error?.stack?.substring(0, 500)
418
421
  });
422
+
423
+ const errorMessage = error?.message ||
424
+ (error?.status ? `Backend request failed with status ${error.status}` : 'Backend validation failed');
425
+
419
426
  throw this.createError(
420
427
  BiometricErrorCode.NETWORK_ERROR,
421
- error?.message || 'Backend validation failed',
422
- error
428
+ errorMessage,
429
+ {
430
+ status: error?.status,
431
+ statusText: error?.statusText,
432
+ errorData: error?.errorData,
433
+ originalError: error?.message
434
+ }
423
435
  );
424
436
  }
425
437
  }
@@ -374,6 +374,13 @@ export class BackendClient {
374
374
  ): Promise<T> {
375
375
  const url = `${this.config.apiEndpoint}${endpoint}`;
376
376
 
377
+ logger.info('Making backend request', {
378
+ url,
379
+ method,
380
+ hasBody: !!body,
381
+ bodySize: body ? JSON.stringify(body).length : 0
382
+ });
383
+
377
384
  const controller = new AbortController();
378
385
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
379
386
 
@@ -393,40 +400,60 @@ export class BackendClient {
393
400
  body: body ? JSON.stringify(body) : undefined,
394
401
  signal: controller.signal as RequestInit['signal'],
395
402
  });
403
+
404
+ logger.info('Backend response received', {
405
+ url,
406
+ status: response.status,
407
+ statusText: response.statusText,
408
+ ok: response.ok
409
+ });
396
410
 
397
411
  clearTimeout(timeoutId);
398
412
 
399
413
  if (!response.ok) {
414
+ let errorText = '';
400
415
  let errorData: Record<string, any> = {};
416
+
401
417
  try {
402
- const text = await response.text();
403
- if (text) {
404
- errorData = JSON.parse(text);
418
+ errorText = await response.text();
419
+ if (errorText) {
420
+ try {
421
+ errorData = JSON.parse(errorText);
422
+ } catch {
423
+ errorData = { raw: errorText };
424
+ }
405
425
  }
406
- } catch {
407
- errorData = {};
426
+ } catch (parseError) {
427
+ logger.warn('Could not parse error response', parseError);
408
428
  }
409
429
 
410
430
  const errorMessage = errorData?.error?.message ||
411
431
  errorData?.detail ||
412
432
  errorData?.message ||
413
- `Request failed with status ${response.status}`;
433
+ errorData?.raw ||
434
+ `Request failed with status ${response.status}: ${response.statusText}`;
414
435
 
415
436
  logger.error('Backend request failed', {
416
437
  url,
417
438
  method,
418
439
  status: response.status,
419
440
  statusText: response.statusText,
420
- errorData
441
+ errorText: errorText.substring(0, 500),
442
+ errorData: JSON.stringify(errorData).substring(0, 500)
421
443
  });
422
444
 
445
+ const error = new Error(errorMessage);
446
+ (error as any).status = response.status;
447
+ (error as any).statusText = response.statusText;
448
+ (error as any).errorData = errorData;
449
+
423
450
  if (response.status === 413) {
424
451
  throw new Error(
425
452
  `Payload too large (413). The request body exceeds the server's size limit. Try reducing the number of video frames or image sizes.`
426
453
  );
427
454
  }
428
455
 
429
- throw new Error(errorMessage);
456
+ throw error;
430
457
  }
431
458
 
432
459
  return await response.json() as T;