Last active
January 23, 2016 00:55
-
-
Save vkostyukov/f759448a430863f9237d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import io.finch._ | |
import com.twitter.finagle.http.Status | |
import io.circe._ | |
import io.circe.generic.auto._ | |
import io.finch.circe._ | |
// Here we tell Finch how to encode exceptions to send them over the wire. | |
val e: Encoder[Exception] = Encoder.instance { | |
case ce: MyError => MyError.jsonEncoder(ce) | |
case t: Throwable => Json.obj("message" -> Json.string(t.getMessage)) | |
} | |
// Here we _handle_ errors - handling is only about whether or not we'll send a remote client | |
// this excpeption over the wire. Unhandled exceptions are converted into 500s without payloads. | |
(ping :+: ep1 :+: ep2 :+: ep3 :+: ep4).handle { | |
case ce: MyError => Output.failure(ce, ce.status) | |
case t: Throwable => | |
logger.warn("Unhandled exception: ", t) | |
Output.failure(new Exception(t), Status.InternalServerError ) | |
}.toService |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment