I have an API gateway in a larger set of microservices, and I'm handling one of my routes. The endpoint ends up making an RPC call to another service, and then I just log the response and send it back to the user. I haven't really completed the error handling section, because was thinking that I could add some middleware later on to handle my errors.
routes.post("/submit", async (request, result) => {
logger.info("Received call to /gapf/submit endpoint");
const gapf = request.body;
// convert relevant request strings into integers
gapf.facultyId = parseInt(gapf.facultyId, 10);
gapf.created = parseInt(gapf.created, 10);
gapf.lastModified = parseInt(gapf.lastModified, 10);
if (gapf.documents !== undefined) {
gapf.documents = gapf.documents.map(doc => {
return {
name: doc.name,
link: doc.link,
attachedDate: parseInt(doc.attachedDate, 10)
};
});
}
try {
logger.info("Calling to Ticket Service with gapf body: %j", gapf);
const response = await tridentClient.SubmitGAPF(gapf);
logger.info("Received response from Ticket Service: %j", response);
logger.info("Exiting /gapf/submit endpoint");
result.json(response);
} catch (err) {
logger.error(
"Received error from submitting to Ticket Service: ",
err.message
);
// TODO: should add middleware later on to handle errors
result.status(500);
result.json({});
}
});
Right now the error.message
seems to be some binary data instead of JSON
, so that would also need to be fixed later on.