Re: [goliath] How to force Goliath validators to return json output?

33 views
Skip to first unread message

Karl Freeman

unread,
Aug 20, 2012, 5:14:17 AM8/20/12
to golia...@googlegroups.com
Try putting the Goliath::Rack::Formatters::JSON above the Goliath::Rack::Validation::RequiredParam in your class.

Cheers
Karl.

On 20 August 2012 10:09, sent-hil <senth...@gmail.com> wrote:
class UsersCreate < Goliath::API
  use Goliath::Rack::Params
  use Goliath::Rack::Validation::RequiredParam, {:key          => 'token',
                                                                              :message => 'is required'}
  use Goliath::Rack::Formatters::JSON
end

In the example above, if no "token" param is passed, Goliath returns "[:error, \"token is required\"]", instead of a Json response. I'm guessing RequiredParam stops the chain if there's no "token", so JSON formatter is never hit.

How do I go about making it return a Json response? Create my own RequiredParam or monkey patch it?

Regards.

sent-hil

unread,
Aug 20, 2012, 5:34:02 AM8/20/12
to golia...@googlegroups.com
Ah damn, I knew it, I posted that and deleted it when I saw your pull request 191 (the one with Render). But, that didn't work either, so I posted again: https://groups.google.com/forum/#!topic/goliath-io/47BSLSVcuMY[1-25]

Sorry for the confusion.

Btw, changing the order doesn't work either.

Regards.
Reply all
Reply to author
Forward
0 new messages