Commit fc9ba58f by G

use of switch case for better flow

parent cdf2a4fb
...@@ -74,20 +74,31 @@ export const getTransactionStatus = async (orderId: string) => { ...@@ -74,20 +74,31 @@ export const getTransactionStatus = async (orderId: string) => {
}); });
log.http("getTransactionStatus |", JSON.stringify(response, null, 2)); log.http("getTransactionStatus |", JSON.stringify(response, null, 2));
if (response.status === "INITIATED") { switch (response.status) {
log.warn("Payment is still in progress, throwing error for mutation to catch"); case "SUCCESS": {
const error = new Error("Payment is still in progress"); log.http("getTransactionStatus |", JSON.stringify(response, null, 2));
error.name = "ORANGE_PAYMENT_IN_PROGRESS"; return response;
throw error; }
} case "INITIATED": {
if (response.status === "FAILED") { log.warn("Payment is still in progress, throwing error for mutation to catch");
log.warn("Payment failed, throwing error for mutation to catch"); const error = new Error("Payment is still in progress");
const error = new Error("Payment failed"); error.name = "ORANGE_PAYMENT_IN_PROGRESS";
error.name = "ORANGE_PAYMENT_FAILED"; throw error;
throw error; }
case "FAILED": {
log.warn("Payment failed, throwing error for mutation to catch");
const error = new Error("Payment failed");
error.name = "ORANGE_PAYMENT_FAILED";
throw error;
}
default: {
log.warn("An unknown error occured, throwing error for mutation to catch");
const error = new Error("Payment failed");
error.name = "UNKNOWN_PAYMENT_ERROR";
throw error;
}
} }
log.http("getTransactionStatus |", JSON.stringify(response, null, 2));
return response;
} catch (error) { } catch (error) {
log.error("getTransactionStatus |", error); log.error("getTransactionStatus |", error);
throw error; throw error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment