Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brandonh-msft opened this issue Feb 28, 2018 · 6 comments
Closed
Assignees
Labels

Comments

@brandonh-msft
Copy link
Member

brandonh-msft commented Feb 28, 2018

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.

@brandonh-msft brandonh-msft changed the title Cannot return 400 BadRequest as response to function runtime [v2] Cannot return 400 BadRequest as response to function runtime Feb 28, 2018
brandonh-msft added a commit to brandonh-msft/serverless-file-validation that referenced this issue Feb 28, 2018
@brettsam brettsam added this to the Triaged milestone Mar 23, 2018
@brettsam brettsam added the bug label Mar 23, 2018
@paulbatum
Copy link
Member

Closing as I believe this is fixed. If you have an up to date repro on the latest bits let us know and I'll reopen!

@dluc
Copy link
Member

dluc commented Aug 2, 2018

I encountered this issue today, I have all the recent libraries and VS up to date. Any suggestion?

@paulbatum
Copy link
Member

I'd start by double checking that you are indeed running on the latest bits. When you run locally, this line specifies the exact host version that is running:

[8/2/2018 1:23:37 AM] Starting Host (HostId=pbatumhost-896498164, InstanceId=206186dc-40f3-4f60-8efa-7fe2bf605912, Version=2.0.11933.0, ProcessId=21384, AppDomainId=1, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)

You should be on 2.0.11933.0 or newer. If you are, then please share repro steps as I am not able to repro with the instructions at the top of this issue.

@fabiocav fabiocav self-assigned this Aug 20, 2018
@fabiocav
Copy link
Member

This is a dupe of Azure/azure-webjobs-sdk#1492

Issue has been resolved there. Will pull packages into the host and add validation tests

@fabiocav
Copy link
Member

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

@fabiocav
Copy link
Member

Closing as resolved.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants