mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Add extra error reporting information in sentry errors
This commit is contained in:
		
							
								
								
									
										19
									
								
								lib/api.dart
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								lib/api.dart
									
									
									
									
									
								
							| @@ -23,7 +23,7 @@ import 'package:inventree/widget/snacks.dart'; | ||||
|  */ | ||||
| class APIResponse { | ||||
|  | ||||
|   APIResponse({this.url = "", this.method = "", this.statusCode = -1, this.data = const {}}); | ||||
|   APIResponse({this.url = "", this.method = "", this.statusCode = -1, this.error = "", this.data = const {}}); | ||||
|  | ||||
|   int statusCode = -1; | ||||
|  | ||||
| @@ -31,6 +31,10 @@ class APIResponse { | ||||
|  | ||||
|   String method = ""; | ||||
|  | ||||
|   String error = ""; | ||||
|  | ||||
|   String errorDetail = ""; | ||||
|  | ||||
|   dynamic data = {}; | ||||
|  | ||||
|   // Request is "valid" if a statusCode was returned | ||||
| @@ -450,6 +454,7 @@ class InvenTreeAPI { | ||||
|       return new APIResponse( | ||||
|         url: url, | ||||
|         method: 'PATCH', | ||||
|         error: "HttpClientRequest is null" | ||||
|       ); | ||||
|     } | ||||
|  | ||||
| @@ -667,8 +672,10 @@ class InvenTreeAPI { | ||||
|       } else { | ||||
|         response.data = await responseToJson(_response) ?? {}; | ||||
|  | ||||
|         if (statusCode != null) { | ||||
|  | ||||
|           // Expected status code not returned | ||||
|         if ((statusCode != null) && (statusCode != _response.statusCode)) { | ||||
|           if (statusCode != _response.statusCode) { | ||||
|             showStatusCodeError(_response.statusCode); | ||||
|           } | ||||
|  | ||||
| @@ -687,14 +694,21 @@ class InvenTreeAPI { | ||||
|             ); | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|  | ||||
|     } on SocketException catch (error) { | ||||
|       showServerError(L10().connectionRefused, error.toString()); | ||||
|       response.error = "SocketException"; | ||||
|       response.errorDetail = error.toString(); | ||||
|  | ||||
|     } on TimeoutException { | ||||
|       showTimeoutError(); | ||||
|       response.error = "TimeoutException"; | ||||
|     } catch (error, stackTrace) { | ||||
|       showServerError(L10().serverError, error.toString()); | ||||
|       sentryReportError(error, stackTrace); | ||||
|       response.error = "UnknownError"; | ||||
|       response.errorDetail = error.toString(); | ||||
|     } | ||||
|  | ||||
|     return response; | ||||
| @@ -754,6 +768,7 @@ class InvenTreeAPI { | ||||
|       return new APIResponse( | ||||
|         url: url, | ||||
|         method: 'GET', | ||||
|         error: "HttpClientRequest is null", | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -114,6 +114,8 @@ class BarcodeHandler { | ||||
|               "url": url, | ||||
|               "statusCode": response.statusCode.toString(), | ||||
|               "valid": response.isValid().toString(), | ||||
|               "error": response.error, | ||||
|               "errorDetail": response.errorDetail, | ||||
|             } | ||||
|         ); | ||||
|       } else if (response.data.containsKey('error')) { | ||||
|   | ||||
| @@ -162,6 +162,8 @@ class InvenTreeModel { | ||||
|           "statusCode": response.statusCode.toString(), | ||||
|           "data": response.data?.toString() ?? "null", | ||||
|           "valid": response.isValid().toString(), | ||||
|           "error": response.error, | ||||
|           "errorDetail": response.errorDetail, | ||||
|         } | ||||
|       ); | ||||
|  | ||||
| @@ -230,7 +232,9 @@ class InvenTreeModel { | ||||
|           "url": url, | ||||
|           "statusCode": response.statusCode.toString(), | ||||
|           "data": response.data?.toString() ?? "null", | ||||
|           "valid": response.isValid().toString() | ||||
|           "valid": response.isValid().toString(), | ||||
|           "error": response.error, | ||||
|           "errorDetail": response.errorDetail, | ||||
|         } | ||||
|       ); | ||||
|  | ||||
| @@ -270,6 +274,8 @@ class InvenTreeModel { | ||||
|           "statusCode": response.statusCode.toString(), | ||||
|           "data": response.data?.toString() ?? "null", | ||||
|           "valid": response.isValid().toString(), | ||||
|           "error": response.error, | ||||
|           "errorDetail": response.errorDetail, | ||||
|         } | ||||
|       ); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user