-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API errror handling #48
Comments
This is issue is becoming more of a priority since the frontend is now setup to make requests to the backend server. We need to standardize how we send response back to the frontend. I've been running into difficulty resolving bugs/issues since there's no consistent structure. To get the conversation started, I'm going to propose that for all responses we continue to send status code number along with a JSON response of the following structure:
To start off, I believe we currently need the following status constants:
Thoughts? |
Can I get assigned to this? |
I like the idea of having a standardized set of responses I would also like to see a catch-all in app.js that would handle anything that manages to fall all the way through. |
Are there errors that need to be refactored while I'm making this? |
@motosharpley yep - agreed on the catch-all for server app.js. I'm still trying to track down how the server is crashing at certain times due to uncaught error that I can't quite trace back to a source...I'm currently guessing its related to one of the promises or call back instances failing and not being appropriately caught. @redragonx all controllers need to be refactored to implement the standard Implementation-wise, I was thinking we could use an event driven mechanism to do this. Open to other implementation suggestions, figured I'd share where I would start if I was going to do this. Also, its imperative that the status constants reside as a true constant object and exported for others to use instead of manually coding each snippet - there should be only one source of truth for ease of testing and modifying across the code base. I would suggest putting it in the |
@jkwening - Okay, this will be likely done in multiple commits or PRs depending on how many controllers there are. Should we talk about future proofing the data objects? I am not too sure on this yet as I'm looking at the data needed still. Just a thought. I was thinking of putting the constants in a file called Thoughts? |
@redragonx yep - multiple commits/PR is definitely fine and encouraged...I'm definitely big fan of piecemeal implementation and updates than one massive code update which can be tricking to test and validate. We currently don't have that many true constants to justify a module just for that. Go ahead and encapsulate the whole error handling into its own module, include status constant object and the logic for now and let's see how it comes together and determine re-packaging later on if needed. I would suggest first building out the module for standardizing the error handling logic and then move onto refactoring the existing code base to utilize it. I've created a new feature branch called "standard-api-error-handling" for this work so it can be completed in isolation of other changes to minimize effects on other feature works. We should work out of that branch until this is done and tested out, then will merge into development. |
Are there any samples of what api error handling looks like? I'm not familiar with the app.res(#).send() notation. |
here is a little snippet of a catchall to help get you started
|
if you scroll down a bit this thread has examples of different approaches, synchronous, event etc. https://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling |
Will each constant have it's own snippet? Or am I checking the request for each error type in the catchall? Can I get a list of endpoints that will expect certain errors? |
Also, what about a logger middleware, any suggestions for that? Found these resources to help guide me design the api error handling |
Regarding my last question about the logger, please ignore it. :) I see that we are using the Morgan logger. |
Here are some additional REST api error formats we can look at: https://nordicapis.com/best-practices-api-error-handling/ I like the Bing and Twitter versions. |
@redragonx the status code constants I was thinking something like this:
So that the same status code strings are utilized whenever responding to a request. |
Still working on this. |
@redragonx glad to hear you're making progress. We're working out of a feature specific branches, so feel free to make PR request as you have parts of it committed and moving along. As usual, let us know if you have any questions or run into issues. |
@jkwening Thanks, I haven't had much time last week to do much, which is annoying to me at least. I'll try to do PRs but no promises. |
Does anyone have good specific examples of Navi api calls that I can test with? @motosharpley @jkwening Thanks! |
@redragonx you can use postman to hit the endpoints and test to see that your getting the expected response back https://www.getpostman.com/ |
Set up error handling in app.js
The text was updated successfully, but these errors were encountered: