Reputation: 12047
I have an Azure Function with a Blob Store input. I can access the input file using the $inputFile
variable, which is super easy.
To allow for dynamic blob selection, I pass a config
query parameter which contains the name of the config to select.
The only issue I have is that if someone passes the name of a non-existent blob, the Azure Function instantly returns a 500 error, which isn't particularly user friendly -
Object reference not set to an instance of an object.
It looks as though this error is generated before execution of my script even begins, so it may not be possible, but is there any way to change this behaviour so that I can send a more helpful message back to the user.
Here are my bindings from function.json, just in case -
{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in",
"authLevel": "function",
"methods": [
"get"
]
},
{
"type": "blob",
"name": "inputBlob",
"path": "configs/{config}.json",
"connection": "AzureWebJobsDashboard",
"direction": "in"
},
{
"name": "res",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
Upvotes: 0
Views: 718
Reputation: 18465
According to your description, I have checked this issue with my Http Trigger using PowserShell, I could encounter the same issue as your mentioned. Also I checked it with Node.js, and this issue still exists. While for C#, we could check the inputBlob
and write the custom process. Per my understanding, if the blob does not exist, the binding would fail for PowserShell, Node.js, etc, and you could not catch the exception and customize your response for now. You could add your issue here or add your feedback here.
Upvotes: 1
Reputation: 1446
Working example.
function.json:
{
"bindings": [
{
"name": "info",
"type": "httpTrigger",
"direction": "in",
"authLevel": "function"
},
{
"name": "inputBlob",
"type": "blob",
"direction": "in",
"path": "configs/{config}.json",
"connection": "AzureWebJobsStorage"
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}
run.csx:
using System.Net;
public class BlobInfo
{
public string config { get; set; }
}
public static HttpResponseMessage Run(HttpRequestMessage req, BlobInfo info, string inputBlob)
{
if (inputBlob == null) {
return req.CreateResponse(HttpStatusCode.NotFound);
}
return req.CreateResponse(HttpStatusCode.OK, new {
data = $"{inputBlob}"
});
}
Upvotes: 1