Skip to content

Commit

Permalink
fix(error fix): added JSON.stringyfy in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
opensrc0 committed Apr 2, 2024
1 parent 8563320 commit 3df39fb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion __app/component/CopyToClipboard/CopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
32 changes: 15 additions & 17 deletions __app/component/LiveLocationTracking/LiveLocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,29 @@ 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`;

try {
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,
Expand Down Expand Up @@ -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 }));
}
};

Expand All @@ -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 });
}
};

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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 },
Expand Down
34 changes: 12 additions & 22 deletions __app/component/LocateMe/LocateMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ 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`;

try {
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,
) => {
Expand All @@ -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,
Expand All @@ -68,21 +66,16 @@ const onSuccss = async (
const zipcode = await getPincode(
position.coords.latitude,
position.coords.longitude,

failureCb,
failureMsg,
);

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,
Expand All @@ -106,7 +99,6 @@ function LocateMe({
if (isPermitByBrowser && isScriptInBrowser) {
navigator.geolocation.getCurrentPosition((position) => {
onSuccss(

successCb,
failureCb,
successMsg,
Expand Down Expand Up @@ -148,7 +140,6 @@ LocateMe.isBrowserSupport = () => navigator.geolocation
&& true;

LocateMe.propTypes = {

successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion __app/component/PhoneBook/PhoneBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion __app/component/Scanner/ScannerCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
};

Expand Down
2 changes: 1 addition & 1 deletion __app/component/Scanner/ScannerGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
};

Expand Down
4 changes: 2 additions & 2 deletions __app/component/Scanner/ScannerInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 3df39fb

Please sign in to comment.