diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2018-01-10 12:09:10 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2018-01-10 12:09:10 +0700 |
commit | 7d9c3a7a0de129eef06d5b2eac92aafec1229098 (patch) | |
tree | 74c839223186e73c017b2e07a5cd43e9754498e5 /src/main/scala/xyz/driver/pdsuicommon | |
parent | 2456ac8336df69734890b325b0b2a5a1182e93e2 (diff) | |
parent | 5bbb0bc66db5b49eb0e3f197be17798fb8093f2a (diff) | |
download | rest-query-7d9c3a7a0de129eef06d5b2eac92aafec1229098.tar.gz rest-query-7d9c3a7a0de129eef06d5b2eac92aafec1229098.tar.bz2 rest-query-7d9c3a7a0de129eef06d5b2eac92aafec1229098.zip |
Merge branch 'master' into PDSUI-2432
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala | 14 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala | 19 |
2 files changed, 3 insertions, 30 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala b/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala index c761414..becb585 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala @@ -16,9 +16,6 @@ object DomainError { // 404 error trait NotFoundError extends DomainError - // 401 error - trait AuthenticationError extends DomainError - // 403 error trait AuthorizationError extends DomainError @@ -28,14 +25,3 @@ object DomainError { Unsafe(Utils.getClassSimpleName(x.getClass)) } } - -/** Subclasses of this exception correspond to subclasses of DomainError. They - * are used in REST service implementations to fail futures rather than - * returning successful futures, completed with corresponding DomainErrors. */ -// scalastyle:off null -@SuppressWarnings(Array("org.wartremover.warts.Null")) -class DomainException(message: String, cause: Throwable = null) extends RuntimeException(message, cause) -class NotFoundException(message: String) extends DomainException(message) // 404 -class AuthenticationException(message: String) extends DomainException(message) // 401 -class AuthorizationException(message: String) extends DomainException(message) // 403 -// scalastyle:on null diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala index 4f53a9d..46b86a6 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala @@ -62,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 } @@ -73,27 +72,15 @@ trait Directives { def errorResponse(msg: String, code: Int) = ErrorsResponse(Seq(ResponseError(None, msg, code)), req) ExceptionHandler { - case ex: AuthenticationException => - complete(StatusCodes.Unauthorized -> errorResponse(ex.getMessage, 401)) - case ex: InvalidActionException => complete(StatusCodes.Forbidden -> errorResponse(ex.message, 403)) - case ex: AuthorizationException => - complete(StatusCodes.Forbidden -> errorResponse(ex.getMessage, 403)) - case ex: ResourceNotFoundException => complete(StatusCodes.NotFound -> errorResponse(ex.message, 404)) - case ex: NotFoundException => - complete(StatusCodes.NotFound -> errorResponse(ex.getMessage, 404)) - case ex: InvalidInputException => complete(StatusCodes.BadRequest -> errorResponse(ex.message, 400)) - case ex: DomainException => - complete(StatusCodes.BadRequest -> errorResponse(ex.getMessage, 400)) - case NonFatal(ex) => complete(StatusCodes.InternalServerError -> errorResponse(ex.getMessage, 500)) } |