crashlytic interceptro
This commit is contained in:
parent
cf8f0b373d
commit
9a61cbecc4
@ -1,3 +1,4 @@
|
|||||||
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:awesome_dio_interceptor/awesome_dio_interceptor.dart';
|
import 'package:awesome_dio_interceptor/awesome_dio_interceptor.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -14,6 +15,7 @@ import 'errors/unauthorized_error.dart';
|
|||||||
import 'interceptors/bad_network_interceptor.dart';
|
import 'interceptors/bad_network_interceptor.dart';
|
||||||
import 'interceptors/bad_request_interceptor.dart';
|
import 'interceptors/bad_request_interceptor.dart';
|
||||||
import 'interceptors/connection_timeout_interceptor.dart';
|
import 'interceptors/connection_timeout_interceptor.dart';
|
||||||
|
import 'interceptors/crashlytic_interceptor.dart';
|
||||||
import 'interceptors/internal_server_interceptor.dart';
|
import 'interceptors/internal_server_interceptor.dart';
|
||||||
import 'interceptors/not_found_interceptor.dart';
|
import 'interceptors/not_found_interceptor.dart';
|
||||||
import 'interceptors/unauthorized_interceptor.dart';
|
import 'interceptors/unauthorized_interceptor.dart';
|
||||||
@ -32,6 +34,7 @@ class ApiClient {
|
|||||||
_dio.interceptors.add(NotFoundErrorInterceptor());
|
_dio.interceptors.add(NotFoundErrorInterceptor());
|
||||||
_dio.interceptors.add(UnauthorizedInterceptor());
|
_dio.interceptors.add(UnauthorizedInterceptor());
|
||||||
_dio.interceptors.add(ConnectionTimeoutErrorInterceptor());
|
_dio.interceptors.add(ConnectionTimeoutErrorInterceptor());
|
||||||
|
_dio.interceptors.add(CrashlyticsInterceptor());
|
||||||
|
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
_dio.interceptors.add(
|
_dio.interceptors.add(
|
||||||
|
|||||||
51
lib/common/api/interceptors/crashlytic_interceptor.dart
Normal file
51
lib/common/api/interceptors/crashlytic_interceptor.dart
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||||
|
|
||||||
|
class CrashlyticsInterceptor extends Interceptor {
|
||||||
|
@override
|
||||||
|
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||||
|
// Log semua error ke Crashlytics
|
||||||
|
FirebaseCrashlytics.instance.recordError(
|
||||||
|
err,
|
||||||
|
err.stackTrace,
|
||||||
|
reason: _getErrorReason(err),
|
||||||
|
information: _getErrorInformation(err),
|
||||||
|
fatal: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
super.onError(err, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getErrorReason(DioException err) {
|
||||||
|
final statusCode = err.response?.statusCode;
|
||||||
|
|
||||||
|
if (statusCode != null) {
|
||||||
|
return 'HTTP $statusCode Error: ${err.requestOptions.uri.path}';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (err.type) {
|
||||||
|
case DioExceptionType.connectionTimeout:
|
||||||
|
return 'Connection Timeout';
|
||||||
|
case DioExceptionType.sendTimeout:
|
||||||
|
return 'Send Timeout';
|
||||||
|
case DioExceptionType.receiveTimeout:
|
||||||
|
return 'Receive Timeout';
|
||||||
|
case DioExceptionType.connectionError:
|
||||||
|
return 'Connection Error';
|
||||||
|
case DioExceptionType.cancel:
|
||||||
|
return 'Request Cancelled';
|
||||||
|
default:
|
||||||
|
return 'Network Error: ${err.type.name}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> _getErrorInformation(DioException err) {
|
||||||
|
return [
|
||||||
|
'URL: ${err.requestOptions.uri}',
|
||||||
|
'Method: ${err.requestOptions.method}',
|
||||||
|
'Status Code: ${err.response?.statusCode ?? 'N/A'}',
|
||||||
|
'Error Type: ${err.type.name}',
|
||||||
|
'Message: ${err.message ?? 'No message'}',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user