Skip to content

Commit bfc58d4

Browse files
committed
fix: handle null statusMessage and improve error message extraction in TokenNotifier
1 parent c4b537a commit bfc58d4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,18 +1149,21 @@ class TokenNotifier extends _$TokenNotifier with ResultHandler {
11491149
// If no specific status message was set, try to extract the error message from the response body
11501150
// or fallback to a generic error message and the status code as details.
11511151
if (statusMessage == null) {
1152+
String? message;
11521153
try {
1153-
final String message = response.body.isNotEmpty
1154+
message = response.body.isNotEmpty
11541155
? (json.decode(response.body)['result']?['error']?['message'] ?? '')
11551156
: '';
1157+
} on FormatException {
1158+
// Format Exception is thrown if the response body is not a valid json. This happens if the server is not reachable.
1159+
}
1160+
if (message == null || message.isEmpty) {
11561161
statusMessage = StatusMessage(
11571162
message: (localization) =>
11581163
localization.errorRollOutFailed(tokenLabel),
11591164
details: (_) => message.toString(),
11601165
);
1161-
} on FormatException {
1162-
// Format Exception is thrown if the response body is not a valid json. This happens if the server is not reachable.
1163-
1166+
} else {
11641167
statusMessage = StatusMessage(
11651168
message: (localization) =>
11661169
localization.errorRollOutFailed(tokenLabel),

0 commit comments

Comments
 (0)