Skip to content

Commit

Permalink
fix: Store actual error in AuthException (#959)
Browse files Browse the repository at this point in the history
fix: store actual error in AuthException
  • Loading branch information
Vinzent03 authored Jul 1, 2024
1 parent d68a9de commit aa6c218
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/gotrue/lib/src/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 4 additions & 1 deletion packages/gotrue/lib/src/types/auth_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa6c218

Please sign in to comment.