Tony Gutierrez
Tony Gutierrez

Reputation: 771

How to trigger a failure in an azure function http trigger, WITH a custom error response

I cannot find a way to fail a http call to a nodejs azure function, and include a custom error response.

Calling context.done() allows for a custom response (but not indicated as a failure in Application Insights)

Calling context.done(true, XXX) does create a failure, but returns a generic error to the user (no matter what I put in XXX):

{"id":"b6ca6fb0-686a-4a9c-8c66-356b6db51848","requestId":"7599d94b-d3f2-48fe-80cd-e067bb1c8557","statusCode":500,"errorCode":0,"message":"An error has occurred. For more information, please check the logs for error ID b6ca6fb0-686a-4a9c-8c66-356b6db51848"}

This is just the latest headache I have ran into in trying to get a fast web api running on Azure funcs. If you cant track errors, than it should hardly be called "Application Insights". Any ideas?

Upvotes: 2

Views: 2018

Answers (2)

Mike S
Mike S

Reputation: 3169

Success will be true, but resultCode will be set to your value.

Try an AppInsights query like this:

// Get all errors
requests
| where toint(resultCode) >= 400
| limit 10

[Update] The Id value in Requests is the 'function instance id', which uniquely identifies that invocation.

There is also a 'traces' table that contains the logging messages from your azure function. You can join between requests and traces via the operation_Id.

requests 
| where toint(resultCode) >= 400
| take 10 
| join (traces) on operation_Id 
| project id, message, operation_Id

The response body is not automatically logged to AppInsights. You'll need to add some explicit log statements to capture that.

Upvotes: 2

Aaron Chen
Aaron Chen

Reputation: 9940

Why not use context.res to return a customer response for an HTTP trigger function?

enter image description here

Upvotes: 1

Related Questions