diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-11-22 16:26:10 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-11-22 19:28:21 +0700 |
commit | 7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c (patch) | |
tree | b2dd987d1e564d986ab50d800a65472240b08595 /src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala | |
parent | a8714cbcf0c19639bc33418e7d3a06b3d0b857ef (diff) | |
download | rest-query-7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c.tar.gz rest-query-7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c.tar.bz2 rest-query-7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c.zip |
Support service exceptions
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala index 93eb62f..ecc30df 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala @@ -13,6 +13,7 @@ import xyz.driver.pdsuicommon.domain._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import xyz.driver.core.generators import xyz.driver.core.rest.ContextHeaders +import xyz.driver.core.rest.errors.{InvalidActionException, InvalidInputException, ResourceNotFoundException} import scala.util.control._ import scala.util._ @@ -61,10 +62,9 @@ trait Directives { PathMatchers.JavaUUID.map((id) => UuidId(id)) def failFast[A](reply: A): A = reply match { - case err: NotFoundError => throw new NotFoundException(err.getMessage) - case err: AuthenticationError => throw new AuthenticationException(err.getMessage) - case err: AuthorizationError => throw new AuthorizationException(err.getMessage) - case err: DomainError => throw new DomainException(err.getMessage) + case err: NotFoundError => throw ResourceNotFoundException(err.getMessage) + case err: AuthorizationError => throw InvalidActionException(err.getMessage) + case err: DomainError => throw InvalidInputException(err.getMessage) case other => other } @@ -72,11 +72,10 @@ trait Directives { def errorResponse(ex: Throwable) = ErrorsResponse(Seq(ResponseError(None, ex.getMessage, 1)), req) ExceptionHandler { - case ex: AuthenticationException => complete(StatusCodes.Unauthorized -> errorResponse(ex)) - case ex: AuthorizationException => complete(StatusCodes.Forbidden -> errorResponse(ex)) - case ex: NotFoundException => complete(StatusCodes.NotFound -> errorResponse(ex)) - case ex: DomainException => complete(StatusCodes.BadRequest -> errorResponse(ex)) - case NonFatal(ex) => complete(StatusCodes.InternalServerError -> errorResponse(ex)) + case ex: InvalidActionException => complete(StatusCodes.Forbidden -> errorResponse(ex)) + case ex: ResourceNotFoundException => complete(StatusCodes.NotFound -> errorResponse(ex)) + case ex: InvalidInputException => complete(StatusCodes.BadRequest -> errorResponse(ex)) + case NonFatal(ex) => complete(StatusCodes.InternalServerError -> errorResponse(ex)) } } |