Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:06:17+00:00 2026-06-15T03:06:17+00:00

Let’s say I want to return a BadRequest result type for all /foo URIs:

  • 0

Let’s say I want to return a BadRequest result type for all /foo URIs:

override def onBadRequest(r: RequestHeader, error: String) = {
  BadRequest("Bad Request: " + error)
}

override def onRouteRequest(r: RequestHeader): Option[Handler] = {
  if(r.uri.startsWith("/foo") onBadRequest("go away")
  else super.onRouteRequest(r)
}

Of course does not work, since the expected return type is Option[play.api.mvc.Handler]

What’s the idiomatic way to deal with this, create a default Application controller method to handle filtered bad requests? Ideally, since I know in onRouteRequest that /foo is in fact a BadRequest, I’d like to call onBadRequest directly.

Should note that this is a contrived example, am actually verifying a URI yyyyMMdd date param, and BadRequest-ing if it does not parse to a JodaTime instance — basically a catch-all filter to sanitize a given date param rather than handling on every single controller method call, not to mention, avoiding cluttering up application log with useless stack traces re: invalid date parse conversions (have several MBs of these junk trace entries accruing daily due to users pointlessly manipulating the uri date in attempts to get at paid subscriber content)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:06:18+00:00Added an answer on June 15, 2026 at 3:06 am

    As usual, the edge goes unanswered…

    Came up with this to sanitize URI date params prior to passing off to Play router

    val ymdMatcher = "\\d{8}".r // matcher for yyyyMMdd URI param
    val ymdFormat = org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd")
    def ymd2Date(ymd: String) = ymdFormat.parseDateTime(ymd)
    
    override def onRouteRequest(r: RequestHeader): Option[Handler] = {
      import play.api.i18n.Messages
      ymdMatcher.findFirstIn(r.uri) map{ ymd=>
        try { ymd2Date( ymd); super.onRouteRequest(r) }
        catch { case e:Exception => // kick to "bad" action handler on invalid date 
          Some(controllers.Application.bad(Messages("bad.date.format"))) 
        }
      } getOrElse(super.onRouteRequest(r))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have thousands of users and I want to make the passwords
Let's say I have a drive such as C:\ , and I want to
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let's say I got a Map<String, String> and I wanna remove all the entries
Let's say I want to write an FTP client from scratch. In the command
Let's say I query for http://images.google.com.sg/images?q=sky&imgcolor=black and I get all the black color sky,
Let's say I have a large amount of files, say 20GB worth, all encrypted
Let's say I have an Instant Messenger server using SignalR. I want to broadcast

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.