Throw additional error on fetch connection to card reader
This commit is contained in:
Vendored
+5
-1
@@ -6,12 +6,16 @@ let removeCRLFfromString = (response_text) => {
|
|||||||
return response_text.replace(/[\n\r]+/g, '').replace(/\s{2,10}/g, ' ');
|
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 = () => {
|
let getMyKadDetail = () => {
|
||||||
return fetch(mykad_reader_endpoint)
|
return fetch(mykad_reader_endpoint)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(response => removeCRLFfromString(response))
|
.then(response => removeCRLFfromString(response))
|
||||||
.then(response => JSON.parse(response))
|
.then(response => JSON.parse(response))
|
||||||
|
.catch(error => {
|
||||||
|
throw myKad_reader_error;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let checkIfMyKadExist = (myKadNumber) => {
|
let checkIfMyKadExist = (myKadNumber) => {
|
||||||
@@ -29,7 +33,7 @@ let handleMyKadReader = () => {
|
|||||||
.then(response => myKadDetail = response[0])
|
.then(response => myKadDetail = response[0])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (myKadDetail.ReadStatus === 'ERROR') {
|
if (myKadDetail.ReadStatus === 'ERROR') {
|
||||||
throw new Error('Sila sambungkan pembaca MyKad dengan betul');
|
throw myKad_reader_error;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => checkIfMyKadExist(myKadDetail.IdNo))
|
.then(() => checkIfMyKadExist(myKadDetail.IdNo))
|
||||||
|
|||||||
Reference in New Issue
Block a user