As you basically just want to re-structure the error, and not completely change the text, you can use a custom error formatter.
Example:
require "grape"
require "json"
module MyErrorFormatter
def self.call message, backtrace, options, env
{ :response_type => 'error', :response => message }.to_json
end
end
class MyApp < Grape::API
prefix 'api'
version 'v1'
format :json
error_formatter :json, MyErrorFormatter
resource :thing do
params do
requires :province, :type => String
end
get do
{ :your_province => params[:province] }
end
end
end
Testing it:
curl http://127.0.0.1:8090/api/v1/thing?province=Cornwall
{"your_province":"Cornwall"}
curl http://127.0.0.1:8090/api/v1/thing
{"response_type":"error","response":"missing parameter: province"}