-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve client-side error response messages
- add custom exception handler + exception case classes - propagate error messages back to the client with 400s if they're known errors & 500 if they're unknown
- Loading branch information
Kelly Innes
committed
Sep 18, 2017
1 parent
570810c
commit cb5cc54
Showing
4 changed files
with
73 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.wikiwatershed.mmw.geoprocessing | ||
|
||
import akka.http.scaladsl.model._ | ||
import akka.http.scaladsl.server._ | ||
import StatusCodes.{BadRequest,InternalServerError} | ||
import Directives._ | ||
|
||
sealed trait GeoprocessingException extends Exception | ||
case class MissingTargetRasterException() extends GeoprocessingException() | ||
case class MissingVectorCRSException() extends GeoprocessingException() | ||
case class MissingVectorException() extends GeoprocessingException() | ||
case class InvalidOperationException(val message: String) extends GeoprocessingException() | ||
case class UnknownCRSException(val crs: String) extends GeoprocessingException() | ||
|
||
trait ErrorHandler { | ||
val geoprocessingExceptionHandler = ExceptionHandler { | ||
case InvalidOperationException(ex) => { | ||
println(s"Invalid operation type: $ex") | ||
complete(HttpResponse(BadRequest, entity = ex)) | ||
} | ||
case MissingTargetRasterException() => { | ||
println("Input error: Missing required targetRaster") | ||
complete(HttpResponse(BadRequest, entity = "Missing required targetRaster")) | ||
} | ||
case ex: MissingVectorCRSException => { | ||
println("Input error: Missing required vectorCRS") | ||
complete(HttpResponse(BadRequest, entity = "Missing required vectorCRS")) | ||
} | ||
case ex: MissingVectorException => { | ||
println(s"Input error: Missing required vector") | ||
complete(HttpResponse(BadRequest, entity = "Missing required vector")) | ||
} | ||
case UnknownCRSException(crs) => { | ||
println(s"Unknown CRS error: $crs") | ||
complete(HttpResponse(BadRequest, entity = "Unknown CRS")) | ||
} | ||
case e: Exception => { | ||
println(s"Exception: $e") | ||
complete(HttpResponse(InternalServerError, entity = s"$e")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters