[v2] Cannot return 400 BadRequest as response to function runtime
See original GitHub issueFunction 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:
- Created 6 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be resolved. Moving this to the next sprint for validation.
Closing as resolved.