Skip to content

Commit

Permalink
#11 Add generic error containing JSON object
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Sep 1, 2017
1 parent 3e7d2d3 commit 549bbe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/org/elastic4play/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ErrorHandler extends HttpErrorHandler {
case iae: IllegalArgumentException Some(Status.BAD_REQUEST Json.obj("type" "IllegalArgument", "message" iae.getMessage))
case _: NoNodeAvailableException Some(Status.INTERNAL_SERVER_ERROR Json.obj("type" "NoNodeAvailable", "message" "ElasticSearch cluster is unreachable"))
case CreateError(_, message, attributes) Some(Status.INTERNAL_SERVER_ERROR Json.obj("type" "CreateError", "message" message, "object" attributes))
case ConflictError(message, attributes) Some(Status.BAD_REQUEST Json.obj("type" "ConflictError", "message" message, "object" attributes))
case ErrorWithObject(tpe, message, obj) Some(Status.BAD_REQUEST Json.obj("type" tpe, "message" message, "object" obj))
case GetError(message) Some(Status.INTERNAL_SERVER_ERROR Json.obj("type" "GetError", "message" message))
case MultiError(message, exceptions)
val suberrors = exceptions.map(e toErrorResult(e)).collect {
Expand Down
11 changes: 8 additions & 3 deletions app/org/elastic4play/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import play.api.libs.json.{ JsObject, JsValue }

import org.elastic4play.controllers.InputValue

class ErrorWithObject(message: String, val obj: JsObject) extends Exception(message)
object ErrorWithObject {
def unapply(ewo: ErrorWithObject): Option[(String, String, JsObject)] = Some((ewo.getClass.getSimpleName, ewo.getMessage, ewo.obj))
}

case class BadRequestError(message: String) extends Exception(message)
case class CreateError(status: Option[String], message: String, attributes: JsObject) extends Exception(message)
case class ConflictError(message: String, attributes: JsObject) extends Exception(message)
case class CreateError(status: Option[String], message: String, attributes: JsObject) extends ErrorWithObject(message, attributes)
case class ConflictError(message: String, attributes: JsObject) extends ErrorWithObject(message, attributes)
case class NotFoundError(message: String) extends Exception(message)
case class GetError(message: String) extends Exception(message)
case class UpdateError(status: Option[String], message: String, attributes: JsObject) extends Exception(message)
case class UpdateError(status: Option[String], message: String, attributes: JsObject) extends ErrorWithObject(message, attributes)
case class InternalError(message: String) extends Exception(message)
case class SearchError(message: String, cause: Throwable) extends Exception(message, cause)
case class AuthenticationError(message: String) extends Exception(message)
Expand Down

0 comments on commit 549bbe8

Please sign in to comment.