Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Created March 24, 2011 17:38
Show Gist options
  • Save eed3si9n/885495 to your computer and use it in GitHub Desktop.
Save eed3si9n/885495 to your computer and use it in GitHub Desktop.
object ErrorAsOk{
import unfiltered.request._
import unfiltered.response._
def unapply[T](request: HttpRequest[T]): Option[Wrapper] = request match {
case Params(params) =>
params("ok") match {
case "" :: xs => Some(NotOkWrapper)
case "0" :: xs => Some(NotOkWrapper)
case "false" :: xs => Some(NotOkWrapper)
case Nil => Some(NotOkWrapper)
case _ => Some(OkWrapper)
}
}
trait Wrapper {
def apply(status: Status): Status
}
object OkWrapper extends Wrapper {
def apply(status: Status): Status = Ok
}
object NotOkWrapper extends Wrapper {
def apply(status: Status): Status = status
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment