Skip to content

Commit 46b282d

Browse files
committed
Adding some error checking into the classmarker webhook controller. Check to see if we've received the required params, if not, raise error in Sentry and return.
1 parent 7139697 commit 46b282d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/controllers/class_marker/webhooks_controller.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
class ClassMarker::WebhooksController < ApplicationController
22
skip_before_action :verify_authenticity_token, :authenticate
33

4-
before_action :verify_hmac_signature
54

65
def assessment
7-
UpdateUserAssessmentAttemptFromClassMarkerJob.perform_later(params[:test][:test_id], params[:result][:cm_user_id], params[:result][:percentage])
6+
test_id = params.dig(:test, :test_id)
7+
cm_user_id = params.dig(:result, :cm_user_id)
8+
percentage = params.dig(:result, :percentage)
9+
10+
if test_id.blank? || cm_user_id.blank? || percentage.blank?
11+
Sentry.capture_message("Classmarker webhook missing parameters", extra: {received_params: params.to_unsafe_h})
12+
head :bad_request
13+
return
14+
end
15+
16+
UpdateUserAssessmentAttemptFromClassMarkerJob.perform_later(test_id, cm_user_id, percentage)
817
head :ok
918
end
1019

0 commit comments

Comments
 (0)