Skip to content

Instantly share code, notes, and snippets.

@benkolera
Created February 5, 2014 04:27
Show Gist options
  • Save benkolera/8817421 to your computer and use it in GitHub Desktop.
Save benkolera/8817421 to your computer and use it in GitHub Desktop.
Argonaut Decode Directive
def decodeJson[A:DecodeJson] = Directive{ req:HttpRequest[Any] =>
def error(msg:String) = Result.Error(
BadRequest ~> ResponseString("Invalid JSON request: " + msg)
)
JsonRequest(req).decode[A] match {
case -\/(-\/(invalidJsonErr)) => error(invalidJsonErr)
case -\/(\/-((decodeFailErr,_))) => error(decodeFailErr)
case \/-(a) => Result.Success(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment