Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Create middleware to read status code from response #316

Open
josh-byster opened this issue Jul 28, 2019 · 3 comments
Open

Create middleware to read status code from response #316

josh-byster opened this issue Jul 28, 2019 · 3 comments
Labels
Priority: Low we can live without this

Comments

@josh-byster
Copy link
Contributor

Currently, the user has to set the error code in 2 places and may forget:

res.status(404).json({
    code: 404,
    message: 'This endpoint must be implemented',
    result: "test"
    success: false
})

As part of issue #69 regarding response standardization, we can parse the code from the response object and send that as the status code, or do the opposite and have the code field be added based on the status method call.

@josh-byster josh-byster added the Priority: Low we can live without this label Jul 28, 2019
@tko22
Copy link
Member

tko22 commented Aug 15, 2019

yes, I'd say the best way to do it would be put it in the json and then we parse the code and put it in the response header.

@josh-byster
Copy link
Contributor Author

Yep, I agree. Problem is that the idea of intercepting and modifying a response as it gets sent out is a more difficult undertaking than I originally envisioned. It looks like we'd have to interface directly with the stream API in Node (example)

@tko22
Copy link
Member

tko22 commented Aug 20, 2019

I think this would be better https://github.com/hack4impact-uiuc/infra-authentication-server/blob/master/src/utils/sendResponse.js#L12

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Priority: Low we can live without this
Projects
None yet
Development

No branches or pull requests

2 participants