Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tototoshi/1798230 to your computer and use it in GitHub Desktop.
Save tototoshi/1798230 to your computer and use it in GitHub Desktop.
scalatraのparams("parameterName")がNoneとかじゃなくてNoSuchElementException返してくるのすごく納得いかない
import java.util.NoSuchElementException
import scala.util.control.Exception._
import org.scalatra._
trait SafeParams { self: ScalatraKernel =>
def paramsSafely(key: String): Option[String] = {
catching(classOf[NoSuchElementException]).opt {
params(key)
}
}
}
/*
import java.util.NoSuchElementException
import scala.util.control.Exception._
import org.scalatra._
trait SafeParams { self: ScalatraKernel =>
def paramsSafely(key: String): Option[String] = {
catching(classOf[NoSuchElementException]).opt {
params(key)
}
}
}
*/
// params 普通にMapだった... params.get("parameterName") で Option が帰る
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment