我正在使用rapidoid构建一个API,并且还接受了另外一个接受application / vnd.api + json而不是application / json的要求。
虽然rapidoid会接受请求并正确处理它,但它会记录错误(如下所示)。有没有办法阻止rapidoid引发此错误或指定应该允许的内容类型列表?
java.lang.RuntimeException: Couldn't parse the request body - unsupported content type: application/vnd.api+json
at org.rapidoid.u.U.rte(U.java:423)
at org.rapidoid.http.impl.ReqImpl.parseRequestBody(ReqImpl.java:812)
at org.rapidoid.http.impl.ReqImpl.posted(ReqImpl.java:244)
at org.rapidoid.http.impl.ReqImpl.posted(ReqImpl.java:330)
at org.rapidoid.http.impl.ReqImpl.data(ReqImpl.java:379)
at org.rapidoid.http.HttpUtils.initAndDeserializeToken(HttpUtils.java:81)
at org.rapidoid.http.impl.ReqImpl.token(ReqImpl.java:694)
at org.rapidoid.http.impl.ReqImpl.hasToken(ReqImpl.java:682)
at org.rapidoid.http.HttpUtils.getAuth(HttpUtils.java:306)
at org.rapidoid.http.handler.HttpAuthWrapper.wrap(HttpAuthWrapper.java:52)
at org.rapidoid.http.handler.HttpManagedHandlerDecorator.wrap(HttpManagedHandlerDecorator.java:185)
at org.rapidoid.http.handler.HttpManagedHandlerDecorator.handleWithWrappers(HttpManagedHandlerDecorator.java:100)
at org.rapidoid.http.handler.HttpManagedHandlerDecorator.access$200(HttpManagedHandlerDecorator.java:39)
at org.rapidoid.http.handler.HttpManagedHandlerDecorator$2.run(HttpManagedHandlerDecorator.java:83)
at org.rapidoid.job.PredefinedContextJobWrapper.run(PredefinedContextJobWrapper.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:0)
您应该使用 ReqRespHandler ,例如:
On.get("/test").html((req, resp)-> "this is a test!");