-
Notifications
You must be signed in to change notification settings - Fork 25
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
res.status() and mung.json() #6
Comments
It's been designed to work with I think your problem is that
See this discussion about |
Awesome! That worked. Is there a way to retrieve the status code on the receiving end? I'm also now having issues now with async methods not getting "munged." I could open a separate ticket for that though if it's better, but something like this: const connection = mysql.createConnection(mysqlConf);
connection.connect();
connection.query('SELECT 1 + 1 as result', function(err, rows, fields) {
if (err) throw err;
res.json(rows).end();
}); is avoiding the munge as well. |
On the server side, you can use This should work:
On the receiver side, it depends on the package you are using to call the server. |
res.status(404).json(response).end(); It doesn't work. Edit: I do get the http response code 404, but the munge function doesn't seem to trigger, is there something I have to do to make it work for non-200 responses? |
Let me write a test. Talk to you in 20 mins. |
Published v0.4.6 that allows munging of error responses. Try this:
|
Works like a charm. Thanks! It's also safe to ignore that async mysql thing I was talking about before. I'm not sure what the issue was but I seem to have solved that as well. This error munging is great because now I can check for some parameter and pass everything as http 200 if needed and append the actual status code in the JSON response. I really appreciate the effort 👍 |
No worries mate, I appreciate the feed back. |
It seems like
res.status()
andmung.json()
don't play well together.I'm fairly new to express in general so I may be doing something wrong here, but I would have expected to be able to do something like:
Once
res.status()
is called, the addMeta method never gets called it seems.What I'm really trying to do here is provide a way for my api to slap on extra meta data at the end of the json response with the http status code for clients that may not be able to receive non-200 http status codes. It would be great to be able to, from the
addMeta
function in my example, make a call likeres.getStatus()
and check the status code that has been set byres.status()
in the previous middleware or route or whatever.The text was updated successfully, but these errors were encountered: