Skip to content

Commit

Permalink
Fix. showing proper error message on api error
Browse files Browse the repository at this point in the history
  • Loading branch information
SanoferSameera committed Oct 17, 2023
1 parent e15d526 commit 6092bb1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/components/demo-auth/demoAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ const DemoAuth = (props) => {
demographics.identifier = { type: "MOBILE", value: demographics.mobileNumber };
response = await authConfirm(props.id, null, demographics);
}
if (("error" in response && response.error !== undefined) || ("Error" in response && response.Error !== undefined)) {
setShowError(true);
if (response.error.code === 1441) {
setErrorMessage("The authentication was unsuccessful. Please check the details you entered.");
} else {
setErrorMessage((response.Error && response.Error.Message) || response.error.message);
}
} else {
isAadhaarDemoAuth ? setAadhaarDemographicsResponse(parseDemographicsNdhmDetails(response)) : setNdhmDetails(parseNdhmDetails(response));
}
setLoader(false);
if(response) {
setLoader(false);
if (response.name !== undefined) {
isAadhaarDemoAuth ? setAadhaarDemographicsResponse(parseDemographicsNdhmDetails(response)) : setNdhmDetails(parseNdhmDetails(response));
}
else {
setShowError(true);
if (response.error !== undefined || response.Error !== undefined) {
console.log("inside if error", response);
if (response.error.code === 1441) {
setErrorMessage("The authentication was unsuccessful. Please check the details you entered.");
} else {
setErrorMessage((response.Error && response.Error.Message) || response.error.message);
}
}
else {
setErrorMessage(response.message || "An error occurred while processing your request");
}
}
}
}

function parseNdhmDetails(patient) {
Expand Down Expand Up @@ -181,8 +190,8 @@ const DemoAuth = (props) => {
<Footer setBack={props.setBack} />
<button className="demo-fetch-button" type="button" disabled={isDisabled} onClick={confirmAuth}>
{isAadhaarDemoAuth ? 'Create ABHA' : 'Fetch ABDM Data'}</button>
{showError && <h6 className="error">{errorMessage}</h6>}
</div>
{showError && <h6 className="error-msg">{errorMessage}</h6>}
</>
}
{loader && <Spinner />}
Expand Down

0 comments on commit 6092bb1

Please sign in to comment.