From c58c9a9a25d72d9f071e9ebf34d23161ffef0f61 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Mon, 9 Mar 2026 20:55:59 -0700 Subject: [PATCH] guard crashlytics call in error handler for test environments Co-Authored-By: Claude Opus 4.6 --- lib/apis/base_api_client.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/apis/base_api_client.dart b/lib/apis/base_api_client.dart index f8eb49c4..d35e84fc 100644 --- a/lib/apis/base_api_client.dart +++ b/lib/apis/base_api_client.dart @@ -179,11 +179,15 @@ abstract class BaseApiClient { if (exception is ServerException || error.type == DioExceptionType.unknown || error.type == DioExceptionType.badCertificate) { - FirebaseCrashlytics.instance.recordError( - exception, - error.stackTrace, - reason: '${error.requestOptions.method} ${error.requestOptions.uri}', - ); + try { + FirebaseCrashlytics.instance.recordError( + exception, + error.stackTrace, + reason: '${error.requestOptions.method} ${error.requestOptions.uri}', + ); + } catch (_) { + // Firebase may not be initialized (e.g., in tests). + } } return exception;