From 938971285e74d443b79a7c161ff18f5a607a5ab4 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Sat, 29 Jun 2024 14:24:35 +0200 Subject: [PATCH] fix: store actual error in AuthException --- packages/gotrue/lib/src/fetch.dart | 9 ++++++--- packages/gotrue/lib/src/types/auth_exception.dart | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/gotrue/lib/src/fetch.dart b/packages/gotrue/lib/src/fetch.dart index b9e21156..7ca92692 100644 --- a/packages/gotrue/lib/src/fetch.dart +++ b/packages/gotrue/lib/src/fetch.dart @@ -30,13 +30,16 @@ class GotrueFetch { AuthException _handleError(dynamic error) { if (error is! Response) { - throw AuthRetryableFetchException(); + throw AuthRetryableFetchException(message: error.toString()); } // If the status is 500 or above, it's likely a server error, // and can be retried. if (error.statusCode >= 500) { - throw AuthRetryableFetchException(); + throw AuthRetryableFetchException( + message: error.body, + statusCode: error.statusCode.toString(), + ); } final dynamic data; @@ -134,7 +137,7 @@ class GotrueFetch { } } catch (e) { // fetch failed, likely due to a network or CORS error - throw AuthRetryableFetchException(); + throw AuthRetryableFetchException(message: e.toString()); } if (!isSuccessStatusCode(response.statusCode)) { diff --git a/packages/gotrue/lib/src/types/auth_exception.dart b/packages/gotrue/lib/src/types/auth_exception.dart index 0584a69c..89030085 100644 --- a/packages/gotrue/lib/src/types/auth_exception.dart +++ b/packages/gotrue/lib/src/types/auth_exception.dart @@ -31,7 +31,10 @@ class AuthSessionMissingException extends AuthException { } class AuthRetryableFetchException extends AuthException { - AuthRetryableFetchException() : super('AuthRetryableFetchError'); + AuthRetryableFetchException({ + String message = 'AuthRetryableFetchException', + super.statusCode, + }) : super(message); } class AuthApiException extends AuthException {