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.

Possible to specify response as combination of status code and body

See original GitHub issue

From reading the docs, it looks like all error responses get the same status code and content type. Is it possible specify these in the handler? For example:

api.get('/', function () {
    if (isBadRequest) return { "message": "Bad request" } // 400 
    if (isForbidden) return { "message": "Forbidden" } // 403 
    return { "message": "Success" } // 200

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:25 (13 by maintainers)

github_iconTop GitHub Comments

fiznoolcommented, Sep 7, 2016

As promised, here are my thoughts on an implementation of multiple error responses.

fiznoolcommented, Aug 30, 2016

@gojko thanks for the detailed response.

For now I’ve taken to using a post deploy step, as you mentioned. It’s a bit of a hack as I didn’t have enough time to look at creating a PR, but it works.

If anybody is interested, the code for my API is here.

One thing I had to also do was to set the error and success codes to the same value, as otherwise claudia sets the default response to return a 500. This often catches all of my errors, regardless of whether I have other regexes in place, this seems to be a quirk of how API Gateway works. I then had to ensure that all of my errors were returned with a prefix in the message, so I could set up my error responses to match the given pattern.

I have some thoughts about how errors could possibly be handled in a more generic way at the claudia level, based on some of my reading around this subject. I’ll try to jot these down over the next few days, probably in a separate issue, for consideration!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
What HTTP status code to return if multiple actions finish with ...
A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. The default ...
Read more >
HTTP/1.1: Response
The first line of a Response message is the Status-Line, consisting of the protocol version followed by a numeric status code and its...
Read more >
Describing Responses - Swagger
A response is defined by its HTTP status code and the data returned in the response body and/or headers. Here is a minimal...
Read more >
Can we create custom HTTP Status codes? - Stack Overflow
Yes you can add custom error codes. If possible use codes that already exist though, and if you are declaring ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found