diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/error')
6 files changed, 0 insertions, 167 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala b/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala deleted file mode 100644 index c761414..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/DomainError.scala +++ /dev/null @@ -1,41 +0,0 @@ -package xyz.driver.pdsuicommon.error - -import xyz.driver.pdsuicommon.logging.{PhiString, Unsafe} -import xyz.driver.pdsuicommon.utils.Utils - -trait DomainError { - - protected def userMessage: String - - def getMessage: String = userMessage - -} - -object DomainError { - - // 404 error - trait NotFoundError extends DomainError - - // 401 error - trait AuthenticationError extends DomainError - - // 403 error - trait AuthorizationError extends DomainError - - implicit def toPhiString(x: DomainError): PhiString = { - // userMessage possibly can contain a personal information, - // so we should prevent it to be printed in logs. - 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/error/ErrorCode.scala b/src/main/scala/xyz/driver/pdsuicommon/error/ErrorCode.scala deleted file mode 100644 index 5574c01..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/ErrorCode.scala +++ /dev/null @@ -1,17 +0,0 @@ -package xyz.driver.pdsuicommon.error - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, Reads, Writes} - -@SuppressWarnings(Array("org.wartremover.warts.Enumeration")) -object ErrorCode extends Enumeration { - - type ErrorCode = Value - val Unspecified = Value(1) - - private val fromJsonReads: Reads[ErrorCode] = Reads.of[Int].map(ErrorCode.apply) - private val toJsonWrites: Writes[ErrorCode] = Writes.of[Int].contramap(_.id) - - implicit val jsonFormat: Format[ErrorCode] = Format(fromJsonReads, toJsonWrites) - -} diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/ErrorsResponse.scala b/src/main/scala/xyz/driver/pdsuicommon/error/ErrorsResponse.scala deleted file mode 100644 index 3761cc5..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/ErrorsResponse.scala +++ /dev/null @@ -1,83 +0,0 @@ -package xyz.driver.pdsuicommon.error - -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import ErrorCode.{ErrorCode, Unspecified} -import ErrorsResponse.ResponseError -import xyz.driver.pdsuicommon.auth.{AnonymousRequestContext, RequestId} -import xyz.driver.pdsuicommon.utils.Utils -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import play.api.mvc.Results -import xyz.driver.pdsuicommon.validation.JsonValidationErrors - -final case class ErrorsResponse(errors: Seq[ResponseError], requestId: RequestId) - -object ErrorsResponse { - - /** - * @param data Any data that can be associated with particular error.Ex.: error field name - * @param message Error message - * @param code Unique error code - * - * @see https://driverinc.atlassian.net/wiki/display/RA/REST+API+Specification#RESTAPISpecification-HTTPStatuscodes - */ - final case class ResponseError(data: Option[String], message: String, code: ErrorCode) - - object ResponseError { - - implicit val responseErrorJsonFormat: Format[ResponseError] = ( - (JsPath \ "data").formatNullable[String] and - (JsPath \ "message").format[String] and - (JsPath \ "code").format[ErrorCode] - )(ResponseError.apply, unlift(ResponseError.unapply)) - - } - - implicit val errorsResponseJsonFormat: Format[ErrorsResponse] = ( - (JsPath \ "errors").format[Seq[ResponseError]] and - (JsPath \ "requestId").format[String] - )((errs, req) => ErrorsResponse.apply(errs, RequestId(req)), res => (res.errors, res.requestId.value)) - - // deprecated, will be removed in REP-436 - def fromString(message: String, httpStatus: Results#Status)( - implicit context: AnonymousRequestContext): ErrorsResponse = { - new ErrorsResponse( - errors = Seq( - ResponseError( - data = None, - message = message, - code = Unspecified - )), - requestId = context.requestId - ) - } - - // scalastyle:off null - def fromExceptionMessage(e: Throwable, httpStatus: Results#Status = Results.InternalServerError)( - implicit context: AnonymousRequestContext): ErrorsResponse = { - val message = if (e.getMessage == null || e.getMessage.isEmpty) { - Utils.getClassSimpleName(e.getClass) - } else { - e.getMessage - } - - fromString(message, httpStatus) - } - // scalastyle:on null - - // deprecated, will be removed in REP-436 - def fromJsonValidationErrors(validationErrors: JsonValidationErrors)( - implicit context: AnonymousRequestContext): ErrorsResponse = { - val errors = validationErrors.map { - case (path, xs) => - ResponseError( - data = Some(path.toString()), - message = xs.map(_.message).mkString("\n"), - code = Unspecified - ) - } - - new ErrorsResponse(errors, context.requestId) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/ExceptionFormatter.scala b/src/main/scala/xyz/driver/pdsuicommon/error/ExceptionFormatter.scala deleted file mode 100644 index c9578b3..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/ExceptionFormatter.scala +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.driver.pdsuicommon.error - -import java.io.{ByteArrayOutputStream, PrintStream} - -object ExceptionFormatter { - - def format(e: Throwable): String = s"$e\n${printStackTrace(e)}" - - def printStackTrace(e: Throwable): String = { - val baos = new ByteArrayOutputStream() - val ps = new PrintStream(baos) - - e.printStackTrace(ps) - - ps.close() - baos.toString() - } -} diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/FailedValidationException.scala b/src/main/scala/xyz/driver/pdsuicommon/error/FailedValidationException.scala deleted file mode 100644 index 7137255..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/FailedValidationException.scala +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.driver.pdsuicommon.error - -import xyz.driver.pdsuicommon.validation.ValidationError - -class FailedValidationException(val error: ValidationError) extends RuntimeException("The validation is failed") diff --git a/src/main/scala/xyz/driver/pdsuicommon/error/IncorrectIdException.scala b/src/main/scala/xyz/driver/pdsuicommon/error/IncorrectIdException.scala deleted file mode 100644 index 5705229..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/error/IncorrectIdException.scala +++ /dev/null @@ -1,3 +0,0 @@ -package xyz.driver.pdsuicommon.error - -final case class IncorrectIdException(message: String) extends Exception(message) |