Nock: how to assert request wasn't made - nock

When a request is made and wasn't mocked I get an error: Error: Nock: No match for request but that doesn't fail the test. Is there a way to make sure no mocked requests were made?

You can catch the "no match" event from nock nock.emitter.on('no match', callback) and use the callback to trigger the error path in your test framework.

Related

Unable to verify event hook

I am testing out the event hook feature in Okta, but when I try to verify the endpoint, the message came out to be:
Unable to verify event hook. Could not deserialize response due to error at Line 1 Column 1
My functions will detect the X-Okta-Verification-Challenge header and outputs a response something like: : { “verification”: “ks58ZrThPLf22kTDavKLhm9aukKNECTmg–3gpsw” }
What am I doing wrong here?
The authentication field, secret and header fields are empty in the settings.
Thanks.

How to catch errors thrown from "FilesInterceptor" decorator

I'm using the NestJS #FilesInterceptor to parse an array of files in a multipart request, here's how I use it:
#FilesInterceptor('files', 3, { some other options })
I need a specific error to be thrown if more than 3 files are sent, but what I get is a socket hangup client-side
Error: socket hang up
and this is the error logged in the console of the server:
Error: Unexpected end of multipart data
In the end: server crashed :(
So, how can I catch this error to handle it and prevent crashing?
It doesn't seem to be an instance of HttpException so the exception filter is not useful.
I could have done the length check in the controller, but I need { some other options }, so I must set a value for the maxCount
I found out the problem: the server has a global interceptor that implements a timeout for incoming requests. If I remove it, then the error is parsed correctly to an HttpException the client gets a BadRequest as expected
I'm still confused about why this doesn't work when I put it all together...

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.

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

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

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)