@proveanything/smartlinks-auth-ui 0.4.3 → 0.4.4

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.
package/dist/index.js CHANGED
@@ -12421,8 +12421,32 @@ function getFriendlyErrorMessage(error) {
12421
12421
  // Fall back to the server's message (already human-readable from backend)
12422
12422
  return error.message;
12423
12423
  }
12424
- // Handle standard Error objects — check message for known patterns
12424
+ // Handle standard Error objects
12425
12425
  if (error instanceof Error) {
12426
+ // SDK bug workaround: SDK may do `throw new Error(responseBodyObject)` which produces
12427
+ // message "[object Object]". Check for API error properties attached to the Error instance.
12428
+ const errAny = error;
12429
+ // Check if the Error has API error properties directly attached (e.g., error.statusCode, error.errorCode)
12430
+ if (typeof errAny.statusCode === 'number' || errAny.errorCode || errAny.response) {
12431
+ // Try to extract from attached properties
12432
+ const apiLike = errAny.response || errAny;
12433
+ if (isApiErrorLike(apiLike)) {
12434
+ return getFriendlyErrorMessage(apiLike);
12435
+ }
12436
+ }
12437
+ // Check if the Error has a `cause` with API error details (modern Error cause pattern)
12438
+ if (errAny.cause && typeof errAny.cause === 'object') {
12439
+ if (isApiErrorLike(errAny.cause)) {
12440
+ return getFriendlyErrorMessage(errAny.cause);
12441
+ }
12442
+ }
12443
+ // If the message is "[object Object]", the error was constructed from a plain object
12444
+ // This is useless - return a generic message instead
12445
+ if (error.message === '[object Object]') {
12446
+ // Log the actual error for debugging
12447
+ console.warn('[AuthKit] Error with [object Object] message. Raw error:', JSON.stringify(errAny, Object.getOwnPropertyNames(errAny)));
12448
+ return 'An unexpected error occurred. Please try again.';
12449
+ }
12426
12450
  // Check if the message itself contains a known API error pattern
12427
12451
  if (/already (registered|exists)/i.test(error.message)) {
12428
12452
  return 'This email is already registered.';
@@ -13253,6 +13277,8 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13253
13277
  }
13254
13278
  }
13255
13279
  catch (err) {
13280
+ // Debug: log the raw error shape to help diagnose SDK error wrapping issues
13281
+ log.error('handleEmailAuth error:', typeof err, err instanceof Error ? `Error.message=${err.message}` : '', JSON.stringify(err, Object.getOwnPropertyNames(err || {})));
13256
13282
  // Check if error is about email already registered (409 conflict)
13257
13283
  // Handle both SmartlinksApiError (statusCode 409) and plain Error with keyword matching
13258
13284
  if (mode === 'register' && (isConflictError(err) ||
@@ -13264,7 +13290,8 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13264
13290
  else {
13265
13291
  setError(getFriendlyErrorMessage(err));
13266
13292
  }
13267
- onAuthError?.(err instanceof Error ? err : new Error(getFriendlyErrorMessage(err)));
13293
+ const friendlyMsg = getFriendlyErrorMessage(err);
13294
+ onAuthError?.(err instanceof Error ? new Error(friendlyMsg) : new Error(friendlyMsg));
13268
13295
  }
13269
13296
  finally {
13270
13297
  setLoading(false);