Skip to content

Commit aa6c218

Browse files
authored
fix: Store actual error in AuthException (#959)
fix: store actual error in AuthException
1 parent d68a9de commit aa6c218

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/gotrue/lib/src/fetch.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ class GotrueFetch {
3030

3131
AuthException _handleError(dynamic error) {
3232
if (error is! Response) {
33-
throw AuthRetryableFetchException();
33+
throw AuthRetryableFetchException(message: error.toString());
3434
}
3535

3636
// If the status is 500 or above, it's likely a server error,
3737
// and can be retried.
3838
if (error.statusCode >= 500) {
39-
throw AuthRetryableFetchException();
39+
throw AuthRetryableFetchException(
40+
message: error.body,
41+
statusCode: error.statusCode.toString(),
42+
);
4043
}
4144

4245
final dynamic data;
@@ -134,7 +137,7 @@ class GotrueFetch {
134137
}
135138
} catch (e) {
136139
// fetch failed, likely due to a network or CORS error
137-
throw AuthRetryableFetchException();
140+
throw AuthRetryableFetchException(message: e.toString());
138141
}
139142

140143
if (!isSuccessStatusCode(response.statusCode)) {

packages/gotrue/lib/src/types/auth_exception.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class AuthSessionMissingException extends AuthException {
3131
}
3232

3333
class AuthRetryableFetchException extends AuthException {
34-
AuthRetryableFetchException() : super('AuthRetryableFetchError');
34+
AuthRetryableFetchException({
35+
String message = 'AuthRetryableFetchException',
36+
super.statusCode,
37+
}) : super(message);
3538
}
3639

3740
class AuthApiException extends AuthException {

0 commit comments

Comments
 (0)