与服务器端的Java异常和500
错误代码http
是否Internal Server Error
有任何关联。这是因为unhandled exceptions
块中的catch
,或者可能是因为unchecked
runtime
例外
我怎么能得出结论,对我而言,Apache Camel
项目有spring-boot-starter-parent
且Spring Quartz
已配置。基本上REST
会通过OAuth 1.0
身份验证检查来调用。
我正在从Swagger
测试我的应用程序。我无法得出结论,
OAuth 1.0
身份验证是否成功error code
,因为unhandled
和runtime exception
基本上Swagger提供以下响应,包含500个错误代码。
"<Error><Message>An error has occurred.</Message><ExceptionMessage>Object reference not set to an instance of an object.</ExceptionMessage><ExceptionType>System.NullReferenceException</ExceptionType><StackTrace> at API.ExecutionTimeFilterAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
\n at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
\n--- End of stack trace from previous location where exception was thrown ---
\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
\n--- End of stack trace from previous location where exception was thrown ---
\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
\n--- End of stack trace from previous location where exception was thrown ---
\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
\n--- End of stack trace from previous location where exception was thrown ---
\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
\n--- End of stack trace from previous location where exception was thrown ---
\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()</StackTrace></Error>"
即使错误secret key
,consumer key
,情况也是如此。
我认为密钥对于这两种情况都是不合适的。
但我想知道,
是500错误代码,对于未处理的异常是常见的未选中 运行时异常或那里我们将是400系列
如果出现http(500)错误代码,除了在代码中处理并作为REST
调用的响应字符串的一部分回复的自定义java错误代码之外,我如何判断测试场景。
答案 0 :(得分:1)
这里你可以做的是添加一个ExceptionHandler并调试 异常的根本原因。看到: https://gitlab-01example.com或 http://www.baeldung.com/exception-handling-for-rest-with-spring或http://zetcode.com/springboot/exceptionhandler/
默认情况下,大多数框架和库(用于构建RESTful API)会对任何未捕获(或运行时)异常抛出500错误,这只是因为它们无法确定实际的业务逻辑。
但服务器端开发人员有责任处理任何未捕获(或运行时)异常,并根据REST API标准或根据业务用例将其转换为正确的HTTP响应代码。有关用例的HTTP响应代码的理想映射,请参阅:http://www.springboottutorial.com/spring-boot-exception-handling-for-rest-services。
P.S。这就像问:我们应该在数组中存储一组整数值 字符串或整数数组。语言/框架没有 强制执行这些细节,对吧? (我的意思是有时他们这样做, 比方说,Java中的泛型,但有一个限制:))