What's the right HTTP status code when REST resource isn't there? - http-status-codes

I'm a bit confused on HTTP status code. Let's say someone calls an endpoint like .../person/15 but there isn't actually a person with identifier 15.
I was previously returning a 412, but as I read that status code closer that's supposed to be related to headers.

That would be 404 (Not Found). If you’re able to detect that the person has been deleted (and their id won’t be reused), use 410 (Gone).

The HTTP status code you may want to use is HTTP/1.1 404 Not Found. There is also a very usefull list with all these codes:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Related

What does "200 connection established" HTTP response status code mean?

I know about 200 OK but what is 200 connection established?
To give some background, I am testing out XMLHTTPRequest in an old firefox browser(version 26 to be exact) and I see this as the response code. I am not able to view either the response headers or body so there definitely seems to be some issue. In newer browsers I see 200 OK and there are no issues with the response. I want to understand what this response code means so that I can debug.
In addition I would like to know if this code indicate a problem with the client or server?
Thanks for any help.
The status code is just "200". What follows is the "reason phrase", and it's up to the server to make one up. Note that in HTTP/2 and /3, there is no reason phrase at all.
So; just ignore it.

express graphql always sends 500 Internal server error for any thrown error from resolver

I am using express graphql in my node app . and it graphql always sends 500 Internal server error for any thrown error from resolver. Please suggest any solution so i will get proper response and status code
The express-graphql sends the HTTP error 500 whenever detects there is no data returned. Definitely, in case of exception is thrown there won't be a returning data. Although it looks like an obvious bug the developers have their own opinion on that. They seemed to decide providing an option to disable the feature so that the server shouldn't set the 500 error. At least the open issue on that is still there.
Checking out the sources I've found these options to get around the problem:
To set any other response code than 200 (e.g. 299 (custom)) in your resolver.
To set the response code in your error formatting handler. This seems to be the most optimal solution.
Just to pick up some other library =)

Golang Http Client request fails on Custom Http Status code

We are rewriting an old integration with a service from python to golang. This service uses Custom status codes. For example the status code is 8000. But while I am trying to get the response it is giving me error as “malformed HTTP status code”. Can some one help me to resolve this issue. Gone through the code and found the following piece of code that throws the error if the status code is not having length of 3.
if len(statusCode) != 3 {
return nil, &badStringError{"malformed HTTP status code", statusCode}
}
EDIT:
I do understand the RFC standard for HTTP status is 3 digits. But I am re-integrating a legacy code of a Banking system. So I cannot / dont have the access to change the service's implementation.
To give more context, python's http library was not doing this validation. (I am not saying that One language is superior to another, so please dont compare the languages/libraries) So wondering if there is any way to bypass this particular validation.
Thanks in advance for understanding..
If you wish you may use standard code for general information (ok, client error, server error, etc) and custom application codes transferred in payload for more details.
From RFC 2616:
The Status-Code element is a 3-digit integer result code of the
attempt
What you have there is not valid HTTP. If you can get hold of the socket directly, you could try parsing the raw TCP data.

Why does Microsoft.AspNetCore.Http.StatusCodes not include 422 Unprocessable Entity?

Microsoft.AspNetCore.Http.StatusCodes contains lots of status code constants useful for returning from a controller and can for example be used like this in a controller:
return StatusCode(StatusCodes.Status201Created);
But oddly the StatusCodes class contains no value for 422 Unprocessable Entity, at least not in Asp.Net Core 1.0.1. Why doesn't it contain StatusCodes.Status422UnprocessableEntity ?
Has this http status code been depreciated by some spec I am unaware of? Or is there some other reason that 422 Unprocessable Entity wasn't included?
Actually it is included in Microsoft.AspNetCore.Http.StatusCodes.
Please find current list in: StatusCodes.cs
HTTP Status Code 422 is WebDAV specific (RFC 4918) and it was added to Microsoft.AspNetCore.Http.StatusCodes a little bit later.
(See details of Added HTTP Status codes #654 pull request)
But it was a few months ago, so the question is what version of ASP.NET Core are you using?
Update:
As Ron C noticed - this status code is included in v1.1 (and not available in v1.0.1).
I wouldn’t know why but I did a quick search and found this post.
As of 2015, #Tom Christie mentioned the following:
Behaviorally both 400 and 422 response codes will be treated the same
by clients and intermediaries, so it actually doesn't make a concrete
difference which you use.
And this:
422 Is specifically a WebDAV extension, and is not referenced in RFC
2616 or in the newer HTTPbis specification.
Maybe...just maybe...the reason why the status code 422 isn’t part of the Microsoft.AspNetCore.Http.StatusCodes might be because it is a WebDAV extension but don’t take my word for it as I’m only trying to raise awareness as to what could be the cause.

Invalid http response 634, 638 - Github webhook

I have a github webhook, it send a post to the url I have set which is not a problem. I have this weird error which I cant find anywhere. It says
Invalid HTTP Response: 634
There is no definition for Response code 634 anywhere? Anyone have any idea about this?
I'm using ruby sinatra to fetch the post and ngrok as my server on localhost itself. Initial requests worked fine.
Once I added code to write the post received to a file in my ruby script, it started giving me this 634 response code, however, it works fine. I'm just curious as to what does the error code imply. I have no issues with my code, it works fine.
Let me know if you need more information.
EDIT:
Earlier one was the response I received when I pushed some changes done to a text file.
Based on mudasobwa's comment, I tried again. This time I checked in a .java file and weirdly I get a different Invalid response 638 this time
I'm not sure whats going on. My server is able to receive the post anyway though.

Resources