Azure / Azure/azure-functions-host

System.FormatException when using function with custom handler as roles source of SWA

Open
#7,865 2 comments 0 reactions 0 assignees View on GitHub
Needs: Attention :wave:
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

#### What language does your question apply to? (e.g. C#, JavaScript, Java, All)
C#, Go

#### Question

I'm using an Azure Function inside a Static Web App. The function is used to get the user roles in `staticwebapp.config.json`:
```
"auth": {
"rolesSource": "/api/GetRoles",
...
}
```
The function itself has a custom handler defined in host.json. The custom handler is implemented in Go:
```
"customHandler": {
"description": {
"defaultExecutablePath": "./build/server",
"workingDirectory": "",
"arguments": []
},
"enableForwardingHttpRequest" : true
},
...
```
The function is called after authentication but a System.FormatException is thrown:
```
Exception while executing function:
Functions.GetRoles The format of value 'text/plain; charset=utf-8, application/json' is invalid.
```
So the `content-type` header is clearly invalid but I don't no why.

According to Azure App Insights the exception originates from `Microsoft.Azure.WebJobs.Script.Extensions.HttpRequestExtensions.ToHttpRequestMessage`, so the exception is actually thrown before my custom handler for the function is called.

Not sure if this is a bug or I'm doing something wrong but any hints would be appreciated.

Contributor guide

Open the contributing guide

Research direction

Start at Microsoft.Azure.WebJobs.Script.Extensions.HttpRequestExtensions.ToHttpRequestMessage and compare the request from the rolesSource in staticwebapp.config.json with the custom handler settings in host.json. Reproduce the /api/GetRoles call and trace how the content-type value is converted; done means the function executes without System.FormatException and returns the roles response.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, go
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.