Skip to content

Commit

Permalink
fix(errors): revamp error in all the component
Browse files Browse the repository at this point in the history
  • Loading branch information
opensrc0 committed May 22, 2024
1 parent edab101 commit 9111d1f
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 36 deletions.
4 changes: 2 additions & 2 deletions __app/component/AutoFillOtp/AutoFillOtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'AutoFillOtp is not supporting in your device',
error: 'Unable to fetch details from AutoFillOtp',
error: '',
};

const isBrowserSupport = () => globalThis.OTPCredential;
Expand Down Expand Up @@ -38,7 +38,7 @@ const autoFillOtp = ({
}).then((otp) => {
const { code } = otp;
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: code });
}).catch((error) => handleError({ msgType: 'ERROR', msg: error, failureCb }));
}).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Unable to fetch details from AutoFillOtp', failureCb }));
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
Expand Down
4 changes: 2 additions & 2 deletions __app/component/ColorPicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'Your browser does not support the Color Picker fetaure',
error: 'Unable to copy color code',
error: '',
};

const isBrowserSupport = () => globalThis.EyeDropper;
Expand All @@ -29,7 +29,7 @@ const colorPicker = ({
.then((result) => {
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: result.sRGBHex });
})
.catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb }));
.catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Unable to copy color code', failureCb }));
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
Expand Down
4 changes: 2 additions & 2 deletions __app/component/CopyToClipboard/CopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'CopyToClipboard is not supporting in your device',
error: 'Unable To Copy',
error: '',
};

const isBrowserSupport = () => globalThis.navigator?.clipboard;
Expand All @@ -27,7 +27,7 @@ const copyToClipboard = ({
// Your Code will start from here
navigator.clipboard.writeText(elementToBeCopy).then(() => {
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: elementToBeCopy });
}).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb }));
}).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Unable To Copy', failureCb }));
// Your Code will end here
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
Expand Down
8 changes: 4 additions & 4 deletions __app/component/FaceDetector/FaceDetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ let videoUnmount = null;
let unmoutRenderLoop = null;
const failureMsgDefault = {
unSupported: 'Face Detector is not supporting in your device',
streamingFailed: 'Camera streaming failed',
barCodeDetectionFailed: 'Bar code detection failed',
streamingFailed: '',
barCodeDetectionFailed: '',
flashUnsupported: 'Flash is not supporting in your device',
};

Expand Down Expand Up @@ -63,7 +63,7 @@ function FaceDetector({
// clearTimeout(unmoutRenderLoop);
}
} catch (error) {
return handleError({ msgType: 'BAR_CODE_DETECTION_FAILED', msg: failureMsg.barCodeDetectionFailed || JSON.stringify(error), failureCb });
return handleError({ msgType: 'BAR_CODE_DETECTION_FAILED', msg: failureMsg.barCodeDetectionFailed || error?.message || 'Bar code detection failed', failureCb });
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ function FaceDetector({
},
});
} catch (error) {
return handleError({ msgType: 'STREAMING_FAILED', msg: failureMsg.streamingFailed || JSON.stringify(error), failureCb });
return handleError({ msgType: 'STREAMING_FAILED', msg: failureMsg.streamingFailed || error?.message || 'Camera streaming failed', failureCb });
}
return mediaStream;
};
Expand Down
2 changes: 1 addition & 1 deletion __app/component/LocateMe/LocateMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const onSuccss = async (
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: zipcode });
};

const onFailure = async (failureCb, error, failureMsg) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error, failureCb });
const onFailure = async (failureCb, error, failureMsg) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error || 'Error occured', failureCb });

const locateMe = ({
successCb = () => {},
Expand Down
4 changes: 2 additions & 2 deletions __app/component/PhoneBook/PhoneBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Wrapper from '../Wrapper/Wrapper';
const failureMsgDefault = {
unSupported: 'PhoneBook is not supporting in your device',
cancelled: 'Feature Cancelled',
error: 'Unable to fetch details from PhoneBook',
error: '',
};

const isBrowserSupport = () => globalThis.navigator?.contacts;
Expand Down Expand Up @@ -35,7 +35,7 @@ const phoneBook = ({
return handleError({ msgType: 'CANCELLED', msg: failureMsg.cancelled, failureCb });
}
} catch (error) {
return handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Unable to fetch details from PhoneBook', failureCb });
}
// Your Code will end here
} else {
Expand Down
5 changes: 2 additions & 3 deletions __app/component/Scanner/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ let unmoutRenderLoop = null;

const failureMsgDefault = {
unSupported: 'QR-Code/Bar-Code/UPI Scanner is not supporting in your device',
streamingFailed: 'Camera streaming failed',
barCodeDetectionFailed: 'Bar code detection failed',
flashUnsupported: 'Flash is not supporting in your device',
error: '',
};

const isBrowserSupport = () => globalThis.navigator?.mediaDevices && globalThis.BarcodeDetector;
Expand Down Expand Up @@ -109,7 +108,7 @@ function Scanner({
},
});
} catch (error) {
return handleError({ msgType: 'STREAMING_FAILED', msg: failureMsg.streamingFailed || JSON.stringify(error), failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Camera streaming failed', failureCb });
}
return mediaStream;
};
Expand Down
6 changes: 3 additions & 3 deletions __app/component/Share/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'Share is not supporting in your device',
badRequest: 'Missing props',
error: 'Unable to share',
badRequest: 'Mandatory props are missing',
error: '',
};

const isShareAPIDataValid = (sharingData) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ const share = ({
if (isShareAPIDataValid(sharingData)) {
navigator.share(sharingData).then(() => {
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: sharingData });
}).catch(() => handleError({ msgType: 'ERROR', msg: failureMsg.error, failureCb }));
}).catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'Unable to share', failureCb }));
} else {
return handleError({ msgType: 'BAD_REQUEST', msg: failureMsg.badRequest, failureCb });
}
Expand Down
5 changes: 2 additions & 3 deletions __app/component/SnapScanner/SnapScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import Wrapper from '../Wrapper/Wrapper';
const failureMsgDefault = {
unSupported: 'SnapScanner is not supporting in your device',
invalidImage: 'Invalid Images',
unableToScan: 'Unable to scan',
error: 'Unable to fetch details from SnapScanner',
error: '',
};

const isBrowserSupport = () => 'BarcodeDetector' in globalThis;
Expand Down Expand Up @@ -47,7 +46,7 @@ const snapScanner = ({
}
return true;
})
.catch((error) => handleError({ msgType: 'UNABLE_TO_SCAN', msg: failureMsg.unableToScan || JSON.stringify(error), failureCb }));
.catch((error) => handleError({ msgType: 'ERROR', msg: failureMsg.error || error.message || 'Unable to scan', failureCb }));
// Your Code will end here
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
Expand Down
10 changes: 5 additions & 5 deletions __app/component/TextToSpeech/TextToSpeech.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const failureMsgDefault = {
badRequest: 'Missing props/params',
techError: 'Technical error',
interrupted: 'Interrupted',
error: 'Unable to convert text to voice',
error: '',
};

const isBrowserSupport = () => globalThis?.speechSynthesis
Expand Down Expand Up @@ -40,12 +40,12 @@ const textToSpeechStart = ({
setIsAudioOn(false);
handleSuccess({ msgType: 'SUCCESSFULFUL', msg: successMsg, successCb, data: text });
};
utteranceCbk.onerror = (e) => {
utteranceCbk.onerror = (event) => {
setIsAudioOn(false);
if (e.error === 'interrupted') {
return handleError({ msgType: 'INTERRUPTED', msg: failureMsg.interrupted || e.error, failureCb });
if (event.error === 'interrupted') {
return handleError({ msgType: 'INTERRUPTED', msg: failureMsg.interrupted, failureCb });
}
return handleError({ msgType: 'ERROR', msg: failureMsg.error || e.error, failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || event.error || 'Unable to convert text to voice', failureCb });
};
} catch (error) {
return handleError({ msgType: 'TECH_ERROR', msg: failureMsg.techError, failureCb });
Expand Down
6 changes: 3 additions & 3 deletions __app/component/VoiceRecognition/VoiceRecognition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import VoiceRecognitionIcon from './VoiceRecognitionIcon';

const failureMsgDefault = {
unSupported: 'VoiceRecognition is not supporting in your device',
error: 'Unable to convert your voice to text',
error: '',
};

const isBrowserSupport = () => globalThis.SpeechRecognition || globalThis.webkitSpeechRecognition;
Expand Down Expand Up @@ -54,9 +54,9 @@ const voiceRecognition = ({
recognition.onsoundend = () => {
setIsVoiceStarted(false);
};
recognition.onerror = () => {
recognition.onerror = (event) => {
setIsModalVisible(false);
return handleError({ msgType: 'ERROR', msg: failureMsg.error, failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || event?.error || 'Unable to convert your voice to text', failureCb });
};
recognition.onend = () => {
recognition.abort();
Expand Down
4 changes: 2 additions & 2 deletions __app/component/WakeLock/WakeLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'WakeLock is not supporting in your device',
error: 'Unable to fetch details from WakeLock',
error: '',
};

const isBrowserSupport = () => globalThis.navigator?.wakeLock;
Expand Down Expand Up @@ -33,7 +33,7 @@ const wakeLock = ({
return handleError({ msgType: 'CANCELLED', failureCb });
}
} catch (error) {
return handleError({ msgType: 'ERROR', msg: failureMsg.error || JSON.stringify(error), failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || error?.message || 'WakeLock failed', failureCb });
}
// Your Code will end here
} else {
Expand Down
7 changes: 3 additions & 4 deletions __app/component/WhatsappShare/WhatsappShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'WhatsappShare is not supporting in your device',
badRequest: 'msg is missing',
error: 'Unable to fetch details from WhatsappShare',
error: '',
};
const isBrowserSupport = () => globalThis;

Expand All @@ -17,7 +16,7 @@ const whatsAppShare = ({
successMsg = 'WhatsappShare details fetch Successfully!!',
failureMsg: failureMsgProps = { ...failureMsgDefault },
mobile,
msg,
msg = '',
} = {}) => {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

Expand All @@ -34,7 +33,7 @@ const whatsAppShare = ({
window.location.href = `https://wa.me/?text=${msg}`;
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: msg });
} else {
return handleError({ msgType: 'BAD_REQUEST', msg: failureMsg.badRequest, failureCb });
return handleError({ msgType: 'ERROR', msg: failureMsg.error || 'Mandatory props are missing', failureCb });
}
} else {
window.location.href = `https://web.whatsapp.com/send?text=${msg}&phone=${mobile}`;
Expand Down

0 comments on commit 9111d1f

Please sign in to comment.