Throw additional error on fetch connection to card reader

This commit is contained in:
afiq.hamzah
2022-08-29 10:30:13 +08:00
parent 6d98730f4a
commit 8148c668f4
+5 -1
View File
@@ -6,12 +6,16 @@ let removeCRLFfromString = (response_text) => {
return response_text.replace(/[\n\r]+/g, '').replace(/\s{2,10}/g, ' ');
};
const myKad_reader_error = new Error('Sila sambungkan pembaca MyKad dengan betul');
let getMyKadDetail = () => {
return fetch(mykad_reader_endpoint)
.then(response => response.text())
.then(response => removeCRLFfromString(response))
.then(response => JSON.parse(response))
.catch(error => {
throw myKad_reader_error;
});
};
let checkIfMyKadExist = (myKadNumber) => {
@@ -29,7 +33,7 @@ let handleMyKadReader = () => {
.then(response => myKadDetail = response[0])
.then(() => {
if (myKadDetail.ReadStatus === 'ERROR') {
throw new Error('Sila sambungkan pembaca MyKad dengan betul');
throw myKad_reader_error;
}
})
.then(() => checkIfMyKadExist(myKadDetail.IdNo))