How to check if all status codes are 200 in Mulesoft 4? - anypoint-studio

Say for example, I created a flow for scatter-gather and I want to check if all endpoints are returning same result status code 200 or throw an error if not.

Configure the Response Validator (General > Response > Response Validator) for each HTTP Request so only 200..299 responses are considered valid.

You can use try block for every HTTP request on wrap whole scatter gather. If one fails, capture HTTP status code in on error propogate and log the results.
I suggest you wrap each request into try block, if you already have a global error handler defined, it should pick up status code 500 etc. Otherwise, capture response code into dataweave

Related

set error http status in response payload in mule 4

my requirement is to sent the error http status and error message in the body.
In Case of error in flow i need to pass the http code in the status field.
I can configure this http listner but don't know how to set this to get into payload. Please guide on that.
I'm expecting the MEL to get the 400 Bad Request
{
'status': "400 Bad Request",
'message': error.description
}
I could think of 2 ways of doing this:
1.You can use RAML and for every status code you can send appropriate responses as per your use case.This I think is the best way of doing it.
2.You can have the value for status and message key of your response body inside error handling block.Configure the 'TYPE' condition of your error handling block to catch a certain HTTP error message , then inside that you can set 2 vars: one with the status value and other with message value.Then use this vars in the Error response section of HTTP listener. You'll be ending up with many such error handling blocks if you want to address multiple status codes.
Let me know if you need further clarifications.Hope it helps.

HTTP status code response when there is not matched data with DB

I am building an API about email auth code.
Its process is simple.
input random code (client browser)
request with input code. (client browser)
receive the request (server)
scan the code from DB (server)
there is no code matched (server)
return a response with status code.
There are many status code, (2xx, 4xx, 5xx);
but I don't know which status code number is the most proper for this case.
It depends on the semantics you want to give your request. E.g.:
The API should search for items matching the query and return a list of results, like GET /codes?q=4ba69g. Think a "search page". In this case, an empty result [] is a perfectly valid result; nothing was wrong with the query, it just didn't return any matches. That's a 200 OK, or maybe a 204 No Content if you want to omit the empty response body entirely.
The code is treated like a resource, e.g. GET /codes/4ba69g. In this case a missing code would result in a 404 Not Found.
It's an action you want to perform which may fail, e.g. POST /login. If the user supplied the wrong credentials/code and hence the action cannot complete, that's a client-side error and therefore a 400 Bad Request.

Identify bad requests(4xx response code) from navigator.sendBeacon()

How can I get response code from navigator.sendBeacon? I need to have some indicator that can say me that request is failed? Particularly, I am looking for a way to identify bad request (request that was send with “bad” malformed json and got 4xx response code). Is there any way to do it while using sendBeacon?
From documentation:
The sendBeacon() method returns true if the user agent is able to
successfully queue the data for transfer, Otherwise it returns false.
So, it is not returning false if request is invalid.(and response code is 4xx)
navigator.sendBeacon(that.sushiEndpoint, sushiPayload)

Is it okay to specify exactly why you are sending an HTTP error code?

If you run an API server then a client sends a bad request, you would usually send him 400 Bad Request error but is it acceptable if you change the message to a more specific one?
Example:
400 Invalid ID
400 Parameter x, y, z is required
400 Minimum length for parameter is x
The canonical place for additional information would be the response body.
There is precedent for using your own codes (which can be handy for log file analysis), but there is nothing wrong with putting whatever description you like in the response.

jmeter help - test around polling /w meta refresh

I am new to jmeter and am working on putting together a test plan. The hurdle I've encountered is as follows:
First, a POST is made to processForm.aspx
Then, the user is redirected to pleaseWait.aspx
This page either redirects immediately to results.aspx OR loads, with a META REFRESH tag set to refresh in 5 seconds (and this step is repeated).
Now -- I can get this to execute by doing the following:
HTTP Sampler POST to processForm.aspx
Assert Response contains "<something on pleaseWait.aspx>"
While LAST
HTTP Sampler GET to pleaseWait.aspx
Assert Response contains "<something on results.aspx>"
However -- I don't care for this method, because it results in failed assertions (even though things are working as expected). I am sure there must be some other way to do this? Anyone more familiar with JMeter than I?
UPDATE:
Got it going by using Regular Expression Extractor instead of Assertions.
1) Add a User Defined Variables section at Test Plan Root
2) Add a variable to it "LoginWait" and "false"
HTTP Sampler POST to processForm.aspx
RegEx Extract Response Body contains "<something on pleaseWait.aspx>" into LoginWait
While ${LoginWait}
HTTP Sampler GET to pleaseWait.aspx
RegEx Extract Response Body contains "<something on pleaseWait.aspx>" into LoginWait
...
You could try using "follow redirects" on your HTTP Request. It would eliminate the logic you need, and still get you to the page you're going.