mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-04-25 01:37:17 +00:00
better job handling
This commit is contained in:
parent
9faceb4f61
commit
ab790e87ff
@ -18,6 +18,9 @@ import spray.json._
|
|||||||
trait HttpHandler extends StrictLogging { this: JsonSupport =>
|
trait HttpHandler extends StrictLogging { this: JsonSupport =>
|
||||||
|
|
||||||
implicit def exceptionHandler: ExceptionHandler = ExceptionHandler {
|
implicit def exceptionHandler: ExceptionHandler = ExceptionHandler {
|
||||||
|
case ex: IllegalArgumentException =>
|
||||||
|
complete(StatusCodes.BadRequest, ErrorResponse(ex.getMessage))
|
||||||
|
|
||||||
case other: Exception =>
|
case other: Exception =>
|
||||||
logger.error("exception during request completion", other)
|
logger.error("exception during request completion", other)
|
||||||
complete(StatusCodes.InternalServerError, ErrorResponse("unknown server error"))
|
complete(StatusCodes.InternalServerError, ErrorResponse("unknown server error"))
|
||||||
|
@ -100,5 +100,10 @@ object Job {
|
|||||||
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, MNK, DRG, NIN, SAM, BRD, MCH, DNC, BLM, SMN, RDM)
|
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, MNK, DRG, NIN, SAM, BRD, MCH, DNC, BLM, SMN, RDM)
|
||||||
lazy val availableWithAnyJob: Seq[Job] = available.prepended(AnyJob)
|
lazy val availableWithAnyJob: Seq[Job] = available.prepended(AnyJob)
|
||||||
|
|
||||||
def withName(job: String): Job.Job = available.find(_.toString == job.toUpperCase).getOrElse(AnyJob)
|
def withName(job: String): Job.Job =
|
||||||
|
availableWithAnyJob.find(_.toString.equalsIgnoreCase(job.toUpperCase)) match {
|
||||||
|
case Some(value) => value
|
||||||
|
case None if job.isEmpty => AnyJob
|
||||||
|
case _ => throw new IllegalArgumentException("Invalid or unknown job")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,12 @@ class JobTest extends WordSpecLike with Matchers with BeforeAndAfterAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"return AnyJob on unknown job" in {
|
"return AnyJob" in {
|
||||||
Job.withName("random string") shouldEqual Job.AnyJob
|
Job.withName("anyjob") shouldEqual Job.AnyJob
|
||||||
|
}
|
||||||
|
|
||||||
|
"fail on unknown job" in {
|
||||||
|
an [IllegalArgumentException] should be thrownBy Job.withName("random string")
|
||||||
}
|
}
|
||||||
|
|
||||||
"equal AnyJob to others" in {
|
"equal AnyJob to others" in {
|
||||||
|
Loading…
Reference in New Issue
Block a user