aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/rest/errors/serviceException.scala
blob: 94f9734a23e51569df6a3b3f64bc97079d2a3e1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package xyz.driver.core.rest.errors

import akka.http.scaladsl.model.{StatusCode, StatusCodes}

abstract class ServiceException extends Exception {
  def isPatientSensitive: Boolean = false

  def statusCode: StatusCode
  def message: String
}

final case class InvalidInputException(override val message: String = "Invalid input",
                                       override val isPatientSensitive: Boolean = false)
    extends ServiceException {
  override def statusCode: StatusCode = StatusCodes.BadRequest
}

final case class InvalidActionException(override val message: String = "This action is not allowed",
                                        override val isPatientSensitive: Boolean = false)
    extends ServiceException {
  override def statusCode: StatusCode = StatusCodes.Forbidden
}

final case class ResourceNotFoundException(override val message: String = "Resource not found",
                                           override val isPatientSensitive: Boolean = false)
    extends ServiceException {
  override def statusCode: StatusCode = StatusCodes.NotFound
}

final case class ExternalServiceTimeoutException(override val message: String =
                                                   "Another service took too long to respond",
                                                 override val isPatientSensitive: Boolean = false)
    extends ServiceException {
  override def statusCode: StatusCode = StatusCodes.GatewayTimeout
}

final case class DatabaseException(override val message: String = "Database access error",
                                   override val isPatientSensitive: Boolean = false)
    extends ServiceException {
  override def statusCode: StatusCode = StatusCodes.InternalServerError
}