question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v2] Cannot return 400 BadRequest as response to function runtime

See original GitHub issue

Function App v2.0 (beta) nupkg v1.0.6+ (have tried .6, .7, and .8)

The following code:

[FunctionName(@"MyFunction")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, @"post")]HttpRequestMessage req, TraceWriter log)
{
	return req.CreateErrorResponse(HttpStatusCode.BadRequest, "Error Message");
}

will result in an error from the function runtime that looks like:

[2/28/2018 11:16:34 PM] A ScriptHost error has occurred
[2/28/2018 11:16:34 PM] Exception while executing function: MyFunction. Autofac: The requested service 'System.Net.Http.Formatting.IContentNegotiator' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
[2/28/2018 11:16:34 PM] Exception while executing function: MyFunction
[2/28/2018 11:16:34 PM] Exception while executing function: MyFunction. Autofac: The requested service 'System.Net.Http.Formatting.IContentNegotiator' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
[2/28/2018 11:16:35 PM] Function completed (Failure, Id=6cf69e24-80aa-49a8-83b4-62819122aa1e, Duration=12084ms)

I’ve tried returning an Exception object (as the overload allows), and also a properly formatted JSON string (eg: { "errors" : "My error message" }) but with no success.

In Functions v1(.0.9 CLI) w/ nupkg v1.0.8, this same code runs successfully and gives back:

[2/28/2018 11:27:44 PM] Response details: {
[2/28/2018 11:27:44 PM]   "requestId": "4f759841-5832-4915-8ca7-75120e3870b6",
[2/28/2018 11:27:44 PM]   "status": "BadRequest"
[2/28/2018 11:27:44 PM] }

as we’d expect.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiocavcommented, Dec 12, 2018

This should be resolved. Moving this to the next sprint for validation.

0reactions
fabiocavcommented, Mar 20, 2019

Closing as resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"func azure functionapp publish" returns error code 400
Response status code does not indicate success: 400 (Bad Request). This didn't give me much info. What does this mean? How can I...
Read more >
Response status code does not indicate success: 400 (Bad ...
The remote server returned an error: (400) Bad Request. Description: An unhandled exception occurred during the execution of the current web ...
Read more >
400 Bad Request Error: What It Is and How to Fix It
The 400 Bad Request Error is an HTTP response status code indicating that the server was unable to process the request sent by...
Read more >
Troubleshoot HTTP 400 errors in IIS
HTTP 400 The webpage cannot be found. ... IIS sends the "HTTP 400 - Bad Request" status back to the client, and then...
Read more >
400 Bad Request - DecompressionFailureAtRequest
The client application gets an HTTP status code of 400 Bad Request with error code messaging.adaptors.http.flow.DecompressionFailureAtRequest as a response ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found