Skip to content

Commit

Permalink
Make sentry not report exceptions from the HTTP client (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAicewizard authored Nov 20, 2024
1 parent af5b4f9 commit 99365b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
10 changes: 9 additions & 1 deletion lib/api/concrexit_api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ class LoggingClient extends oauth2.Client {

@override
Future<StreamedResponse> send(BaseRequest request) async {
final response = await super.send(request);
StreamedResponse response;
try {
response = await super.send(request);
} catch (e) {
if (kDebugMode) {
print('url: ${request.url}, failed: $e');
}
rethrow;
}
if (kDebugMode) {
print('url: ${request.url}, response code: ${response.statusCode}');
}
Expand Down
11 changes: 7 additions & 4 deletions lib/blocs/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ class AuthCubit extends Cubit<AuthState> {
),
);
},
httpClient: SentryHttpClient(failedRequestStatusCodes: [
SentryStatusCode(400),
SentryStatusCode.range(405, 499),
]),
httpClient: SentryHttpClient(
failedRequestStatusCodes: [
SentryStatusCode(400),
SentryStatusCode.range(405, 499),
],
captureFailedRequests: false,
),
),
config: apiConfig,
onLogOut: logOut,
Expand Down
17 changes: 11 additions & 6 deletions lib/blocs/list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ abstract class ListCubit<F, T, S> extends Cubit<S> {
List<Future<List<T>>> futuresUp = [];
List<Future<List<T>>> futuresDown = [];
for (final source in sources) {
source._nextOffsetUp = 0;
source._nextOffsetDown = 0;
source.isDoneUp = false;
source.isDoneDown = false;
try {
source._nextOffsetUp = 0;
source._nextOffsetDown = 0;
source.isDoneUp = false;
source.isDoneDown = false;
futuresUp.add(source.moreUp());
futuresDown.add(source.moreDown());
} on ApiException catch (exception) {
Expand All @@ -115,8 +115,13 @@ abstract class ListCubit<F, T, S> extends Cubit<S> {
cleanupOldState();
List<List<T>> resultsUp = [];
List<List<T>> resultsDown = [];
resultsUp = await Future.wait(futuresUp);
resultsDown = await Future.wait(futuresDown);
try {
resultsUp = await Future.wait(futuresUp);
resultsDown = await Future.wait(futuresDown);
} on ApiException catch (exception) {
safeEmit(failure(exception.message));
return;
}

// Discard result if _searchQuery has
// changed since the request was made.
Expand Down

0 comments on commit 99365b6

Please sign in to comment.