Skip to content

Commit

Permalink
refactor: explicitly defined response errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amosmachora committed Jul 31, 2024
1 parent fa8b491 commit a8f9d79
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/esm-billing-app/src/m-pesa/mpesa-resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ export const initiateStkPush = async (
}),
});

if (!res.ok && res.status === 403) {
const error = new Error('Health facility M-PESA data not configured.');
throw error;
if (res.ok) {
const response: { requestId: string } = await res.json();
setNotification({ message: 'STK Push sent successfully', type: 'success' });
return response.requestId;
}

const response: { requestId: string } = await res.json();
setNotification({ message: 'STK Push sent successfully', type: 'success' });
if (!res.ok && res.status === 403) {
setNotification({
message: 'Health facility M-PESA data not configured.',
type: 'error',
});

return response.requestId;
return;
}

if (!res.ok) {
throw new Error('Unable to initiate Lipa Na Mpesa, please try again later.');
}
} catch (err) {
setNotification({
message: 'Unable to initiate Lipa Na Mpesa, please try again later.',
Expand Down

0 comments on commit a8f9d79

Please sign in to comment.