Skip to content

Commit

Permalink
[SPARK-24660][SHS] Show correct error pages when downloading logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed Jun 26, 2018
1 parent e07aee2 commit 8b26a53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.util.zip.ZipOutputStream
import javax.servlet.ServletContext
import javax.servlet.http.HttpServletRequest
import javax.ws.rs._
import javax.ws.rs.core.{Context, Response}
import javax.ws.rs.core.{Context, MediaType, Response}

import org.eclipse.jetty.server.handler.ContextHandler
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
Expand Down Expand Up @@ -148,38 +148,36 @@ private[v1] trait BaseAppResource extends ApiRequestContext {
}

private[v1] class ForbiddenException(msg: String) extends WebApplicationException(
Response.status(Response.Status.FORBIDDEN).entity(msg).build())
Response.status(Response.Status.FORBIDDEN).entity(msg).`type`(MediaType.TEXT_PLAIN).build())

private[v1] class NotFoundException(msg: String) extends WebApplicationException(
new NoSuchElementException(msg),
Response
.status(Response.Status.NOT_FOUND)
.entity(ErrorWrapper(msg))
.entity(msg)
.`type`(MediaType.TEXT_PLAIN)
.build()
)

private[v1] class ServiceUnavailable(msg: String) extends WebApplicationException(
new ServiceUnavailableException(msg),
Response
.status(Response.Status.SERVICE_UNAVAILABLE)
.entity(ErrorWrapper(msg))
.entity(msg)
.`type`(MediaType.TEXT_PLAIN)
.build()
)

private[v1] class BadParameterException(msg: String) extends WebApplicationException(
new IllegalArgumentException(msg),
Response
.status(Response.Status.BAD_REQUEST)
.entity(ErrorWrapper(msg))
.entity(msg)
.`type`(MediaType.TEXT_PLAIN)
.build()
) {
def this(param: String, exp: String, actual: String) = {
this(raw"""Bad value for parameter "$param". Expected a $exp, got "$actual"""")
}
}

/**
* Signal to JacksonMessageWriter to not convert the message into json (which would result in an
* extra set of quotes).
*/
private[v1] case class ErrorWrapper(s: String)
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{
mediaType: MediaType,
multivaluedMap: MultivaluedMap[String, AnyRef],
outputStream: OutputStream): Unit = {
t match {
case ErrorWrapper(err) => outputStream.write(err.getBytes(StandardCharsets.UTF_8))
case _ => mapper.writeValue(outputStream, t)
}
mapper.writeValue(outputStream, t)
}

override def getSize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ private[v1] class AbstractApplicationResource extends BaseAppResource {
.header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
.build()
} catch {
case NonFatal(e) =>
case NonFatal(_) =>
Response.serverError()
.entity(s"Event logs are not available for app: $appId.")
.`type`(MediaType.TEXT_PLAIN)
.status(Response.Status.SERVICE_UNAVAILABLE)
.build()
}
Expand Down

0 comments on commit 8b26a53

Please sign in to comment.