Skip to content

Commit

Permalink
fix(error): add stacktrace info
Browse files Browse the repository at this point in the history
Signed-off-by: Taranjeet Singh <[email protected]>
  • Loading branch information
singhtaranjeet committed Aug 25, 2023
1 parent d1c9a1a commit aedd501
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 15 additions & 3 deletions lib/src/exceptions/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,32 @@ class RequestCancelError extends DioError {
response,
type = DioErrorType.other,
error,
this.showStackTrace = false,
}) : super(
requestOptions: requestOptions,
response: response,
type: type,
error: error,
);

RequestCancelError.fromDioError(DioError error)
: super(
RequestCancelError.fromDioError(DioError error, bool showStackTrace)
: showStackTrace = showStackTrace,
super(
type: error.type,
error: error.error,
requestOptions: error.requestOptions,
response: error.response,
);

/// showStackTrace true means DEV flavor
final bool showStackTrace;

@override
String toString() => error;
String toString() {
if (!showStackTrace) {
return "Error: ${response?.statusCode ?? ""} Something Went Wrong!";
}

return "Token Cancelled Error: ${response?.statusCode ?? ""} ${error ?? response?.statusMessage ?? ""}";
}
}
7 changes: 6 additions & 1 deletion lib/src/interceptors/error_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ abstract class ErrorInterceptor extends Interceptor {
}

if (error.type == DioErrorType.cancel) {
return handler.reject(RequestCancelError.fromDioError(error));
return handler.reject(
RequestCancelError.fromDioError(
error,
showStackTrace,
),
);
}

return handler.reject(
Expand Down

0 comments on commit aedd501

Please sign in to comment.