- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个函数来读取存储中的自定义文件。 function.json 与此类似:
{
"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"
}
]
}
在 postman 中,如果我键入现有文件,它将正确调用该函数。另一方面,如果该文件不存在,azure 运行时将抛出错误:
{ "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
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
instance,Object[] arguments)\r\n at async
Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker
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
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)" }
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
我想在找不到文件时发送 404 状态代码,而不是像那样丑陋的堆栈(以及错误 500)。我应该遵循的最佳方法是什么?
==更新
请注意,FunctionInitationException 发生在调用我的函数之前。 Azure Functions Runtime 中似乎存在一个错误,我不知道这是错误还是预期错误。
最佳答案
我们还可以在Azure函数应用程序中捕获异常。在您的情况下,您可以捕获异常并返回 http 状态代码 HttpStatusCode.NotFound
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
try
{
//Todo :Add your own logic
}
catch (Exception ex)
{
return req.CreateResponse(HttpStatusCode.NotFound);
}
return req.CreateResponse(HttpStatusCode.OK);
}
编辑:
正如您提到的,它发生在调用函数之前,似乎是由Azure函数集成SDK返回的。这也许是设计好的。我们也可以将我们的想法发送给azure function team .
如果我们想控制逻辑,我的解决方法是我们可以删除输入 blob 并自己实现自定义逻辑。我们可以从 Microsoft Azure Storage SDK for Node.js 获取示例代码.
关于azure - 找不到 blob 文件时出现 FunctionInitationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46552859/
我正在创建一个函数来读取存储中的自定义文件。 function.json 与此类似: { "disabled": false, "bindings": [ { "authL
我正在创建一个函数来读取存储中的自定义文件。 function.json 与此类似: { "disabled": false, "bindings": [ { "authL
我在 Azure WebJob 中收到此错误。知道可能是什么原因造成的吗? 我正在使用 Ninject 在我的 Azure WebJobs 控制台应用程序中处理 DI。 我已经为我的所有服务设置了 B
我编译的 Azure 函数在 DLL 中找不到由我的函数调用的 DLL 调用的方法。 Microsoft.Azure.WebJobs.Host.FunctionInvocationException
我编译的 Azure 函数在 DLL 中找不到由我的函数调用的 DLL 调用的方法。 Microsoft.Azure.WebJobs.Host.FunctionInvocationException
我是一名优秀的程序员,十分优秀!