Skip to content

Commit

Permalink
Gracefully rescue_from CeleryScript::TypeCheckError
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Jan 20, 2019
1 parent d4371e0 commit 568f8bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/api/abstract_controller.rb
@@ -1,3 +1,5 @@
require "./app/lib/celery_script/checker"

module Api
# A controller that contains all of the helper methods and shared logic for
# all API endpoints.
Expand All @@ -16,6 +18,10 @@ class OnlyJson < Exception; end;
skip_before_action :verify_authenticity_token
after_action :skip_set_cookies_header

rescue_from(CeleryScript::TypeCheckError) do |err|
sorry err.message, 422
end

rescue_from(ActionController::RoutingError) { sorry "Not found", 404 }
rescue_from(User::AlreadyVerified) { sorry "Already verified.", 409 }

Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/api/regimens/regimens_create_spec.rb
Expand Up @@ -59,5 +59,29 @@
expect(json[:name]).to eq(name)
expect(json[:color]).to eq(color)
end

it "handles CeleryScript::TypeCheckError" do
sign_in user
s = FakeSequence.with_parameters
payload = { device: s.device,
name: "specs",
color: "red",
body: [
{
kind: "variable_declaration",
args: {
label: "parent",
data_value: { kind: "nothing", args: { } }
}
}
],
regimen_items: [
{ time_offset: 100, sequence_id: s.id }
] }
post :create, body: payload.to_json, format: :json
expect(response.status).to eq(422)
expect(json.fetch(:error))
.to include("must provide a value for all parameters")
end
end
end

0 comments on commit 568f8bd

Please sign in to comment.