Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue addressable uri error with proper error message #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def index
render :json => {:status => "Error", :message => @page.all_full_messages.join(",")}, :status => 400, :callback => params[:callback]
end
end

rescue Addressable::URI::InvalidURIError
render :json => {:status => "Error", :message => "That is not a proper URL" }, :status => 400, :callback => params[:callback]
end

def show
Expand Down
11 changes: 11 additions & 0 deletions spec/requests/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
parsed_json["message"].should =~ /Domain must be a \.gov/
end
end

context "when the url is malformed" do
it "should return an error" do
get "/pages", :url => 'http:', :callback => "callback"
response.status.should == 400
response.body.should =~/^callback\(.*\)$/
parsed_json = JSON.parse(response.body.slice(/^callback\((.*)\)$/, 1))
parsed_json["status"].should == "Error"
parsed_json["message"].should == 'That is not a proper URL'
end
end
end
end

Expand Down