Skip to content
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

Unhandled server error response handler #41

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

moyo-paystack
Copy link
Contributor

Changes

  • A new method for returning responses based on unhandled code errors

@ife-paystack
Copy link
Collaborator

Looks neat. I'm however curious as to how other errors (such as validation, not found) and even success responses would be handled.
Would we create response files for all of those and then call them individually as per return successResponse(2xx, message, data), and return return badRequest(4xx, message, err)`

Or is there some benefit in having a single response helper where all the responses are consolidated?

@opeyemi-paystack
Copy link
Contributor

Would we create response files for all of those and then call them individually as per return successResponse(2xx, message, data), and return return badRequest(4xx, message, err)`

Yeah I second this. I thought we were going to have sendSuccess and sendError. Then in sendError there's a param called type/code that determines what to do. e.g. If it's 500 log the error, send to slack etc, but for 400 and others just send the 400 like that idk.

@opeyemi-paystack
Copy link
Contributor

Nice on @moyo-paystack. We've not caught unhandled exceptions in this PR though.

The way i've seen it done in express is pretty straightforward. e.g.

// catch 404 and forward to error handler
app.use((req, res, next) => {
  next(createError(404));
});

// error handler
app.use((err, req, res, next) => {
  res.status(err.status || 500).send({'status': 'error', 'data': err.message});
});

@moyo-paystack
Copy link
Contributor Author

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

@opeyemi-paystack
Copy link
Contributor

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

Nice @moyo-paystack! What do you think about having a response handler that houses the various response functions? I'm not sure we need each function in a separate file cc @ife-paystack

responses/successResponse.js Outdated Show resolved Hide resolved
responses/successResponse.js Outdated Show resolved Hide resolved
responses/successResponse.js Outdated Show resolved Hide resolved
@ife-paystack
Copy link
Collaborator

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

Nice @moyo-paystack! What do you think about having a response handler that houses the various response functions? I'm not sure we need each function in a separate file cc @ife-paystack

Yes, this was exactly my thought too, this method you've implemented would mean we have a response file for each error code?

@moyo-paystack
Copy link
Contributor Author

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

Nice @moyo-paystack! What do you think about having a response handler that houses the various response functions? I'm not sure we need each function in a separate file cc @ife-paystack

Yes, this was exactly my thought too, this method you've implemented would mean we have a response file for each error code?

I could make each response to be in one file. I separated the 4xx and 5xx into separate response methods cos I think it's easier to follow.

@moyo-paystack
Copy link
Contributor Author

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

@ife-paystack and @opeyemi-paystack I have made changes to the PR based on the discussion here. Please take another look

Nice @moyo-paystack! What do you think about having a response handler that houses the various response functions? I'm not sure we need each function in a separate file cc @ife-paystack

Yes, this was exactly my thought too, this method you've implemented would mean we have a response file for each error code?

I could make each response to be in one file. I separated the 4xx and 5xx into separate response methods cos I think it's easier to follow.

I've moved all the responses to one file

responses/index.js Outdated Show resolved Hide resolved
@ife-paystack
Copy link
Collaborator

Tests 👀 @moyo-paystack

@ife-paystack
Copy link
Collaborator

Tests 👀 @moyo-paystack

👀

@moyo-paystack
Copy link
Contributor Author

Tests 👀 @moyo-paystack

👀

Lol @ife-paystack sorry for the non-reply. Will get on to the tests later this evening.

@kachi-paystack
Copy link
Collaborator

@moyo-paystack please help resolve conflicts on this and push again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants