Laravel Lighthouse GraphQL validation response code is 200 instead of 422 - laravel

Why validation response code and unathuntication status code is 200(ok) instead of 422 and 401 ?
how can i find request is failed to show error to users when all response codes are 200?

Have a look at this thread for an explanation why it's 200 always: https://github.com/nuwave/lighthouse/issues/279

Related

When testing error scenarios how do you configure JMeter to show these tests as passed

I have some validations in my Rest API that will return 400 bad request. I have added test cases in JMeter for these, however the Listeners (e.g. Tree view) show these as unsuccessful (Error Icon) because JMeter did not receive a 200 response. Is there a way to indicate for a given HTTP request that 400 is the expected result. I can add an assert but the tree view display still shows the red error icon.
You verify the Response Code, 400 and the Response Message,bad request with Response Assertions.
Add two Response Assertions to the HTTP Request where you need to verify the error.
Let's say you want to verify the response code first. Select Field to Test as Response Code in the first Response Assertion. Select the Ignore Status field. Set the Pattern Matching Rules as Equal. Click Add button and type the response code to verify, 400.
Please ensure the Ignore Status is selected only in the first assertion.
In the second Response Assertion we shall verify the response message. Select the Field to Test as Response Message, Pattern Matching Rules as Contains, click the Add button and the add the regular expression to check.
You're getting the error because JMeter automatically treats responses with HTTP Status Codes above 399 as failures.
If you expect HTTP Status Code 400 and would like to mark the request(s) as passed - add a Response Assertion and configure it to check that response code equals to 400 and additionally tick "Ignore Status" box:

Response Status: 200 OK but Response body is Null in JMETER

For one of my Requests in jmeter, I am getting Response code as 200 OK but Response body is NULL.
Due to this "Response Assertion" is failing since we are expecting Response to generate.
Here i am unable to get as to why the status code is 200 even though Response body is null.
Sampler result showing Response status as 200
Response Data SS
Response assertion
If you're expecting HTTP Status Code to be 200 and not interested in the body - amend your Response Assertion configuration as follows:
Fields to Test: Response Code
Pattern Matching Rules: Equals
Patterns to Test: 200
This way your assertion will pass.
Check out Response Assertions in JMeter 3.2 - New and Improved article for more information on using Response Assertion to conditionally mark Samplers as passed or failed
If you expect the request to return some body data - then assertion failure is correct and I can think of the following options:
You're sending a malformed request hence not getting a response, cross check the request with the API contract or with the other API testing tools like SoapUI or Postman
There is a bug in your application. Status code 200 doesn't necessarily mean success and vice versa
If the situation happens only under the load it might be the case you found the bottleneck

Http response status in headers or in content

I have to write an application which serves HTTP request.
For these requests application has to send the response content with status**.
Status is integer which represents status code.( 1 : Session Expired, 2: Invalid Request Data. etc,.)
There are 2 options.
One is to send the status code with content itself:
Ex : {status : 56, content: [{name:'pinto', id: 90}]}
Another one is specifying the status code in header itself, so that once I receive the header from client if status states the there is an error I can abort the request so that I don't have to receive the response body and process it.
I think second option will be better than first one, because
No need to get for the response content which is very much helpful in case of content is large.
Is this is recommended solution or any other suggestions ?
You should be using HTTP status codes for this kind of thing.
Session Expired: 401 Unauthorized - authentication is possible but has failed
Invalid Request Data:
400 Bad Request - request cannot be fulfilled due to bad syntax
405 Method Not Allowed - request method not supported by that resource
409 Conflict - request could not be processed because of conflict
413 Request Entity Too Large - request is larger than the server is willing or able to process
422 Unprocessable Entity - request unable to be followed due to semantic errors

jQuery $.get/$.ajax passes HTTP status code 200 instead of expected status code of 201 or 202

I've a server that returns HTTP status code 200, 201, and 202 from the same url. In Chrome, I've confirmed with the Network debugging panel that the Status Code is what I expect it to be (i.e. 200, 201 or 202). I rely on that status code to determine the next step.
I'd expect that the callbacks for jQuery (version 1.5.2) AJAX requests to set jqxhr.status to the status code that the server sends. However, the status code is always 200, even if the code sent by the server is 201 or 202.
In other words, the following code prints Code: 200 regardless of what the server sends.
$.get(url, {}, function (data, textStatus, xhr ) {
alert("Code: " + xhr.status);
});
Why is this happening, and more importantly, how can one get the actual status code in a jQuery AJAX callback for $.get or $.ajax?
Thank you for reading.
From what I have experienced jQuery is just not set up very well for handling actual status codes in the response. You can try just doing a manual AJAX call using some good old bare bones JS and handle the status yourself.
Here are a few tutorials on how to do so.
http://www.degraeve.com/reference/simple-ajax-example.php
http://www.w3schools.com/ajax/default.asp
request.status is where you should be able to access the status code in your request object. Here is another page showing a little bit about how to access even more granular information about the status of the request.
http://www.ibm.com/developerworks/web/library/wa-ajaxintro3/
Hope that helps you nail it!

Detect a 304 redirection on an AJAX request

is there a way to detect whether an AJAX request has been redirected through a 304 response ? I tried an onreadystagechange with xhr.status==304 but got nothing. Are we only bound to 200 response codes ?
The issue was already raised on SO but I couldn't find any answer...
if (xhr.status == 304){
//do your code
}
It should 100% work

Resources