[KYUUBI #4977] Log error message when REST API invocation error occurs
### _Why are the changes needed?_ Currently, there is no error message on Kyuubi server's log when REST API invocation error occurs, and since we are building REST API, all response media types should be JSON. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request Closes #4977 from pan3793/error-log. Closes #4977 00c2b0c0f [Cheng Pan] Update kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/api.scala 5fe00474f [Cheng Pan] trino f988329f8 [Cheng Pan] nit 74f9ed762 [Cheng Pan] log error message for REST api invocation Authored-by: Cheng Pan <chengpan@apache.org> Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
parent
facbd78383
commit
34bb1d4dbe
@ -25,6 +25,7 @@ import javax.ws.rs.ext.{ExceptionMapper, Provider}
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler
|
||||
|
||||
import org.apache.kyuubi.Logging
|
||||
import org.apache.kyuubi.server.KyuubiRestFrontendService
|
||||
|
||||
private[api] trait ApiRequestContext {
|
||||
@ -39,18 +40,19 @@ private[api] trait ApiRequestContext {
|
||||
}
|
||||
|
||||
@Provider
|
||||
class RestExceptionMapper extends ExceptionMapper[Exception] {
|
||||
class RestExceptionMapper extends ExceptionMapper[Exception] with Logging {
|
||||
override def toResponse(exception: Exception): Response = {
|
||||
warn("Error occurs on accessing REST API.", exception)
|
||||
exception match {
|
||||
case e: WebApplicationException =>
|
||||
Response.status(e.getResponse.getStatus)
|
||||
.`type`(e.getResponse.getMediaType)
|
||||
.entity(e.getMessage)
|
||||
.`type`(MediaType.APPLICATION_JSON)
|
||||
.entity(Map("message" -> e.getMessage))
|
||||
.build()
|
||||
case e =>
|
||||
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.`type`(MediaType.APPLICATION_JSON)
|
||||
.entity(e.getMessage)
|
||||
.entity(Map("message" -> e.getMessage))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import javax.ws.rs.ext.{ExceptionMapper, Provider}
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler
|
||||
|
||||
import org.apache.kyuubi.Logging
|
||||
import org.apache.kyuubi.server.KyuubiTrinoFrontendService
|
||||
|
||||
private[api] trait ApiRequestContext {
|
||||
@ -39,18 +40,19 @@ private[api] trait ApiRequestContext {
|
||||
}
|
||||
|
||||
@Provider
|
||||
class RestExceptionMapper extends ExceptionMapper[Exception] {
|
||||
class RestExceptionMapper extends ExceptionMapper[Exception] with Logging {
|
||||
override def toResponse(exception: Exception): Response = {
|
||||
warn("Error occurs on accessing Trino API.", exception)
|
||||
exception match {
|
||||
case e: WebApplicationException =>
|
||||
Response.status(e.getResponse.getStatus)
|
||||
.`type`(e.getResponse.getMediaType)
|
||||
.entity(e.getMessage)
|
||||
.`type`(MediaType.APPLICATION_JSON)
|
||||
.entity(Map("message" -> e.getMessage))
|
||||
.build()
|
||||
case e =>
|
||||
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.`type`(MediaType.APPLICATION_JSON)
|
||||
.entity(e.getMessage)
|
||||
.entity(Map("message" -> e.getMessage))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user