From 3df39fb5a4f9c32013fd766ca3635c335972371e Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Tue, 2 Apr 2024 18:26:51 +0530 Subject: [PATCH] fix(error fix): added JSON.stringyfy in case of error --- .../CopyToClipboard/CopyToClipboard.js | 2 +- .../LiveLocationTracking.js | 32 ++++++++--------- __app/component/LocateMe/LocateMe.js | 34 +++++++------------ __app/component/PhoneBook/PhoneBook.js | 2 +- __app/component/Scanner/ScannerCamera.js | 2 +- __app/component/Scanner/ScannerGallery.js | 2 +- __app/component/Scanner/ScannerInit.js | 4 +-- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/__app/component/CopyToClipboard/CopyToClipboard.js b/__app/component/CopyToClipboard/CopyToClipboard.js index a8f21f3..590b6d5 100644 --- a/__app/component/CopyToClipboard/CopyToClipboard.js +++ b/__app/component/CopyToClipboard/CopyToClipboard.js @@ -17,7 +17,7 @@ function CopyToClipboard({ handleLoading({ loadingCb }); navigator.clipboard.writeText(elementToBeCopy).then(() => { handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: elementToBeCopy }); - }).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error, failureCb })); + }).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb })); } else { return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb }); } diff --git a/__app/component/LiveLocationTracking/LiveLocationTracking.js b/__app/component/LiveLocationTracking/LiveLocationTracking.js index e783e8f..86d763d 100644 --- a/__app/component/LiveLocationTracking/LiveLocationTracking.js +++ b/__app/component/LiveLocationTracking/LiveLocationTracking.js @@ -8,17 +8,17 @@ const checkPermitByBrowser = async (failureMsg, failureCb) => { try { const permissions = await navigator.permissions.query({ name: 'geolocation' }); if (permissions.state === 'denied') { - return handleError({ msgType: 'PERMISSION_DENIED', msg: failureMsg.permissionDenied || 'Permission Denied', failureCb }); + return handleError({ msgType: 'PERMISSION_DENIED', msg: failureMsg.permissionDenied, failureCb }); } } catch (error) { - return handleError({ msgType: 'BROWSER_PERMISION_API_FAILED', msg: failureMsg.browserPermissionAPIFailed || 'Unable to check browser permission', failureCb }); + return handleError({ msgType: 'BROWSER_PERMISION_API_FAILED', msg: failureMsg.browserPermissionAPIFailed, failureCb }); } return true; }; const checkScriptInBrowser = async (failureMsg, failureCb, isProdKey, googleKey) => { if (!googleKey) { - return handleError({ msgType: 'GOOGLE_API_KEY_MISSING', msg: failureMsg.googleAPIKeyMissing || 'Unable to check browser permission', failureCb }); + return handleError({ msgType: 'GOOGLE_API_KEY_MISSING', msg: failureMsg.googleAPIKeyMissing, failureCb }); } const googleApiUrl = `https://maps.googleapis.com/maps/api/js?${isProdKey ? 'client' : 'key'}=${googleKey}&libraries=places&loading=async`; @@ -26,12 +26,11 @@ const checkScriptInBrowser = async (failureMsg, failureCb, isProdKey, googleKey) await dependentJsService(googleApiUrl, 'googleMapLocationAPI', true); return true; } catch (error) { - return handleError({ msgType: 'UNABLE_TO_LOAD_GOOGLE_APIS', msg: failureMsg.unableToLoadGoogleAPI || 'Unable to load google api script', failureCb }); + return handleError({ msgType: 'UNABLE_TO_LOAD_GOOGLE_APIS', msg: failureMsg.unableToLoadGoogleAPI, failureCb }); } }; function LiveLocationTracking({ - successCb, failureCb, successMsg, @@ -75,7 +74,7 @@ function LiveLocationTracking({ .then((response) => { directionsRenderer.setDirections(response); handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: currentLocations }); - }).catch(() => handleError({ msgType: 'UNABLE_TO_LOCATE_DIRECTION', msg: failureMsg.unableToLocateDirection || 'Unable To get Updated Location', failureCb })); + }).catch(() => handleError({ msgType: 'UNABLE_TO_LOCATE_DIRECTION', msg: failureMsg.unableToLocateDirection, failureCb })); } }; @@ -84,7 +83,7 @@ function LiveLocationTracking({ if (error.code === 1 && error.message === 'User denied Geolocation') { handleError({ msgType: 'PERMISSION_DENIED', msg: failureMsg.permissionDenied || 'Permission Denied', failureCb }); } - handleError({ msgType: 'LOCATION_NOT_FOUND', msg: failureMsg.locationNotFound || 'Unable To get Updated Location', failureCb }); + handleError({ msgType: 'LOCATION_NOT_FOUND', msg: failureMsg.locationNotFound, failureCb }); } }; @@ -114,7 +113,7 @@ function LiveLocationTracking({ locationError(), { enableHighAccuracy: true, timeout: 30000, maximumAge: 2000, distanceFilter: 100 }, ); - }, 100); + }, 200); } } else { return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb }); @@ -158,15 +157,14 @@ LiveLocationTracking.defaultProps = { loadingCb: () => {}, successMsg: '', failureMsg: { - unSupported: '', - permissionDenied: '', - unableToLocateDirection: '', - browserPermissionCheckFailed: '', - unableToLoadGoogleAPI: '', - locationNotFound: '', - scriptNotLoaded: '', - invalidLatLng: '', - googleAPIKeyMissing: '', + unSupported: 'LiveLocationTracking is not supporting in your device', + permissionDenied: 'Permission Denied', + unableToLocateDirection: 'Unable To get Updated Location', + browserPermissionAPIFailed: 'Unable to check browser permission', + unableToLoadGoogleAPI: 'Unable to load google api script', + locationNotFound: 'Unable To get Updated Location', + // invalidLatLng: '', + googleAPIKeyMissing: 'Unable to check browser permission', error: '', }, destinationLatLng: { lat: 12.9541033, lng: 77.7091133 }, diff --git a/__app/component/LocateMe/LocateMe.js b/__app/component/LocateMe/LocateMe.js index c98e715..62f054b 100644 --- a/__app/component/LocateMe/LocateMe.js +++ b/__app/component/LocateMe/LocateMe.js @@ -8,17 +8,17 @@ const checkPermitByBrowser = async (failureMsg, failureCb) => { try { const permissions = await navigator.permissions.query({ name: 'geolocation' }); if (permissions.state === 'denied') { - return handleError({ msgType: 'PERMISSION_DENIED', msg: failureMsg.permissionDenied || 'Permission Denied', failureCb }); + return handleError({ msgType: 'PERMISSION_DENIED', msg: failureMsg.permissionDenied, failureCb }); } } catch (error) { - return handleError({ msgType: 'BROWSER_PERMISION_API_FAILED', msg: failureMsg.browserPermissionAPIFailed || 'Unable to check browser permission', failureCb }); + return handleError({ msgType: 'BROWSER_PERMISION_API_FAILED', msg: failureMsg.browserPermissionAPIFailed, failureCb }); } return true; }; const checkScriptInBrowser = async (failureMsg, failureCb, isProdKey, googleKey) => { if (!googleKey) { - return handleError({ msgType: 'GOOGLE_API_KEY_MISSING', msg: failureMsg.googleAPIKeyMissing || 'Google Key is missing', failureCb }); + return handleError({ msgType: 'GOOGLE_API_KEY_MISSING', msg: failureMsg.googleAPIKeyMissing, failureCb }); } const googleApiUrl = `https://maps.googleapis.com/maps/api/js?${isProdKey ? 'client' : 'key'}=${googleKey}&libraries=places&loading=async`; @@ -26,14 +26,13 @@ const checkScriptInBrowser = async (failureMsg, failureCb, isProdKey, googleKey) await dependentJsService(googleApiUrl, 'googleMapLocationAPI', true); return true; } catch (error) { - return handleError({ msgType: 'UNABLE_TO_LOAD_GOOGLE_APIS', msg: failureMsg.unableToLoadGoogleAPI || 'Unable to load google api script', failureCb }); + return handleError({ msgType: 'UNABLE_TO_LOAD_GOOGLE_APIS', msg: failureMsg.unableToLoadGoogleAPI, failureCb }); } }; const getPincode = async ( latitude, longitude, - failureCb, failureMsg, ) => { @@ -51,14 +50,13 @@ const getPincode = async ( return zipcode; } } catch (err) { - return handleError({ msgType: 'INVALID_LAT_LNG', msg: failureMsg.invalidLatLng || 'Invalid Lat lng', failureCb }); + return handleError({ msgType: 'INVALID_LAT_LNG', msg: failureMsg.invalidLatLng, failureCb }); } return ''; }; const onSuccss = async ( - successCb, failureCb, successMsg, @@ -68,7 +66,6 @@ const onSuccss = async ( const zipcode = await getPincode( position.coords.latitude, position.coords.longitude, - failureCb, failureMsg, ); @@ -76,13 +73,9 @@ const onSuccss = async ( handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: zipcode }); }; -const onFailure = async (failureCb, error, failureMsg) => { - failureCb(error); - return handleError({ msgType: 'ERROR', msg: failureMsg.error || error, failureCb }); -}; +const onFailure = async (failureCb, error, failureMsg) => handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb }); function LocateMe({ - successCb, failureCb, successMsg, @@ -106,7 +99,6 @@ function LocateMe({ if (isPermitByBrowser && isScriptInBrowser) { navigator.geolocation.getCurrentPosition((position) => { onSuccss( - successCb, failureCb, successMsg, @@ -148,7 +140,6 @@ LocateMe.isBrowserSupport = () => navigator.geolocation && true; LocateMe.propTypes = { - successCb: PropTypes.func, failureCb: PropTypes.func, loadingCb: PropTypes.func, @@ -159,18 +150,17 @@ LocateMe.propTypes = { }; LocateMe.defaultProps = { - successCb: () => {}, failureCb: () => {}, loadingCb: () => {}, successMsg: 'Located Successfully', failureMsg: { - unSupported: '', - permissionDenied: '', - browserPermissionAPIFailed: '', - googleAPIKeyMissing: '', - unableToLoadGoogleAPI: '', - invalidLatLng: '', + unSupported: 'LocationMe is not supporting in your device', + permissionDenied: 'Permission Denied', + browserPermissionAPIFailed: 'Unable to check browser permission', + googleAPIKeyMissing: 'Google Key is missing', + unableToLoadGoogleAPI: 'Unable to load google api script', + invalidLatLng: 'Invalid Lat lng', error: '', }, isProdKey: true, diff --git a/__app/component/PhoneBook/PhoneBook.js b/__app/component/PhoneBook/PhoneBook.js index 3b416ba..3008963 100644 --- a/__app/component/PhoneBook/PhoneBook.js +++ b/__app/component/PhoneBook/PhoneBook.js @@ -25,7 +25,7 @@ function PhoneBook({ return handleError({ msgType: 'CANCELLED', msg: failureMsg.cancelled, failureCb }); } } catch (error) { - return handleError({ msgType: 'ERROR', msg: failureMsg.error || error, failureCb }); + return handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb }); } } else { return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb }); diff --git a/__app/component/Scanner/ScannerCamera.js b/__app/component/Scanner/ScannerCamera.js index 90b76d9..c177088 100644 --- a/__app/component/Scanner/ScannerCamera.js +++ b/__app/component/Scanner/ScannerCamera.js @@ -37,7 +37,7 @@ function ScannerCamera({ } return true; }) - .catch((error) => handleError({ msgType: 'UNABLE_TO_SCAN', msg: failureMsg.unableToScan || error, failureCb })); + .catch((error) => handleError({ msgType: 'UNABLE_TO_SCAN', msg: failureMsg.unableToScan || JSON.stringify(error), failureCb })); } }; diff --git a/__app/component/Scanner/ScannerGallery.js b/__app/component/Scanner/ScannerGallery.js index bc9daeb..87d4342 100644 --- a/__app/component/Scanner/ScannerGallery.js +++ b/__app/component/Scanner/ScannerGallery.js @@ -38,7 +38,7 @@ function ScannerGallery({ } return true; }) - .catch((error) => handleError({ msgType: 'UNABLE_TO_SCAN', msg: failureMsg.unableToScan || error, failureCb })); + .catch((error) => handleError({ msgType: 'UNABLE_TO_SCAN', msg: failureMsg.unableToScan || JSON.stringify(error), failureCb })); } }; diff --git a/__app/component/Scanner/ScannerInit.js b/__app/component/Scanner/ScannerInit.js index ad6e89d..51d25c9 100644 --- a/__app/component/Scanner/ScannerInit.js +++ b/__app/component/Scanner/ScannerInit.js @@ -56,7 +56,7 @@ function ScannerInit({ } }); }) - .catch((error) => handleError({ msgType: 'BAR_CODE_DETECTION', msg: failureMsg.barCodeDetection || error, failureCb })) + .catch((error) => handleError({ msgType: 'BAR_CODE_DETECTION', msg: failureMsg.barCodeDetection || JSON.stringify(error), failureCb })) ) : null; } @@ -103,7 +103,7 @@ function ScannerInit({ }, }); } catch (error) { - return handleError({ msgType: 'STREAMING_ERROR', msg: failureMsg.streaming || error, failureCb }); + return handleError({ msgType: 'STREAMING_ERROR', msg: failureMsg.streaming || JSON.stringify(error), failureCb }); } return mediaStream; };