question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some thoughts on returning json / text

See original GitHub issue

I like this idea a lot, especially when it comes to error handling.

However, by far the most common use case would be to send json or text. What would you think about the following:

  • when the promise rejects, call next(err)
  • when the promise resolves with text, call res.send(text)
  • when the promise resolves anything else, call res.json(obj)
  • next() and next('route') seem like exceptional cases to me, what about just not handling those?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
joepie91commented, Feb 7, 2016

This seems like dangerous functionality. Especially with implicit returns (ES6 arrow functions, CoffeeScript, …), it would be very easy to accidentally return (and thus expose) data that the user is never meant to see.

0reactions
mormahrcommented, Apr 16, 2017

As the last comment is over a year old i’d like to close this issue (and #11). But if anyone is interested in pushing these thoughts in a new direction (eg. by wrapping the response or by configuring this functionality “opt-in”) we could open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I return JSON in HTTP response? - ReqBin
To return JSON from the server, you must include the JSON data in the body of the HTTP response message and provide a...
Read more >
MVC: How to Return a String as JSON - Stack Overflow
The contents of the file are pre-serialized to JSON. This is to ensure that there is nothing standing in the way of the...
Read more >
rest api - JSON String in response shows up with quotes
The client call to the REST API returns with qoutes around the reqult like this example: "...result.." and also with \" inside the...
Read more >
Format response data in ASP.NET Core Web API
For example, returning JsonResult returns JSON-formatted data and returning ContentResult returns plain-text-formatted string data. An action ...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
For example, JSON.stringify on the same object will always produce the same string, and JSON.parse(JSON.stringify(obj)) would produce an object ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found