Je crée une fonction qui lit un fichier personnalisé dans notre stockage. Le function.json est similaire à celui-ci:FunctionInvocationException lorsque le fichier blob n'est pas trouvé
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "resource/{code}",
"methods": [
"get"
]
},
{
"type": "blob",
"name": "item",
"path": "data/20171003/{code}.json",
"connection": "blog_STORAGE",
"direction": "in"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
En postier, si je tape un fichier existant, il correctement appeler la fonction. Si le fichier n'existe pas, d'autre part, le moteur d'exécution d'azur renvoie une erreur:
{ "id": "4ef77dcd-f8ed-4327-9447-969da6b328a9", "requestId": "0a9874dd-6a7b-4717-ae9f-c3c1e3bb16c8", "statusCode": 500, "errorCode": 0, "message": "Exception while executing function: Functions.func_ativos -> Valor não pode ser nulo.\r\nNome do parâmetro: stream", "errorDetails": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.func_ativos ---> System.ArgumentNullException : Valor não pode ser nulo.\r\nNome do parâmetro: stream\r\n at System.IO.StreamReader..ctor(Stream stream,Encoding encoding,Boolean detectEncodingFromByteOrderMarks,Int32 bufferSize,Boolean leaveOpen)\r\n at System.IO.StreamReader..ctor(Stream stream)\r\n
at Microsoft.Azure.WebJobs.Script.Binding.FunctionBinding.ConvertStreamToValue(Stream stream,DataType dataType,Object& converted)\r\n at async Microsoft.Azure.WebJobs.Script.Binding.FunctionBinding.BindStreamAsync(BindingContext context,FileAccess access)\r\n at async Microsoft.Azure.WebJobs.Script.Binding.ExtensionBinding.BindAsync(BindingContext context)\r\n at async Microsoft.Azure.WebJobs.Script.Description.NodeFunctionInvoker.ProcessInputBindingsAsync(Binder binder,Dictionary2 executionContext,Dictionary
2 bindingData)\r\n
at async Microsoft.Azure.WebJobs.Script.Description.NodeFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context)\r\n at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker2.InvokeAsync[TReflected,TReturnType](TReflected instance,Object[] arguments)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker
2.InvokeAsync[TReflected,TReturnValue](Object[] arguments)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,ILogger logger,CancellationTokenSource functionCancellationTokenSource)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) \r\n End of inner exception\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)\r\n at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()\r\n at async Microsoft.Azure.WebJobs.JobHost.CallAsync(??)\r\n at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary2 arguments,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ProcessRequestAsync(HttpRequestMessage request,FunctionDescriptor function,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.<>c__DisplayClass3_0.<ExecuteAsync>b__0(??)\r\n at async Microsoft.Azure.WebJobs.Extensions.Http.HttpRequestManager.ProcessRequestAsync(HttpRequestMessage request,Func
3 processRequestHandler,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\r\n at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)" }
Je veux envoyer un code d'état 404 lorsque le fichier est introuvable, pas une pile laid comme ça (et erreur 500). Quelle est la meilleure approche que je devrais suivre?
mise à jour ==
S'il vous plaît noter que FunctionInvocationException se avant ma fonction est appelée. Il semble une erreur dans Azure Functions Runtime que je ne peux pas savoir si est un bug ou attendu.
J'utilise des fonctions javascript, mais je pense que le problème est le même: l'erreur se produit avant que ma fonction est appelée (et il est jamais appelé dans ce cas). Je ne peux pas attraper l'exception par des moyens normaux, je pense. –
Je m'attendais à recevoir la liaison vide si le fichier n'existe pas, pas une erreur dans l'exécution des fonctions azure. Je ne peux même pas savoir si c'est un bug ou attendu. –
J'ai mis à jour la réponse, nous pourrions supprimer la liaison d'entrée et utiliser [SDK] (https://github.com/Azure/azure-storage-node) pour le faire. –