Created
March 24, 2011 17:38
-
-
Save eed3si9n/885495 to your computer and use it in GitHub Desktop.
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
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