Skip to content

Commit

Permalink
show error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwoldatwork committed Dec 11, 2024
1 parent b07aa92 commit 4545658
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app/views/components/widget/_fba.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,21 @@ function FBAform(d, N) {
}
alertErrorElement.removeAttribute("hidden");
const errorMessage = this.formComponent().querySelector('.usa-alert--error');
if (errorMessage) {
errorMessage.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
} else { // OTHER SERVER ERROR
this.successState = false;
d.dispatchEvent(new Event('onTouchpointsFormSubmissionError'));
alertErrorElement.removeAttribute("hidden");
alertErrorElementBody.innerHTML += "Server error. We're sorry, but this submission was not successful. The Product Team has been notified.";
const errorMessage = this.formComponent().querySelector('.usa-alert--error');
if (errorMessage) {
errorMessage.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
}
},
Expand Down
13 changes: 8 additions & 5 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
class Rack::Attack
throttle('limit_form_submissions', limit: 6, period: 1.minute) do |req|
if req.post? && route_matches?(req, :submit_form)
throttle('limit_form_submissions_per_minute', limit: 6, period: 1.minute) do |req|
if req.post? && (route_matches?(req, :touchpoint_submissions) || route_matches?(req, :form_submissions))
req.ip # Throttle based on the request's IP address
end
end

# Helper method to check if the route matches the named route
# Check if the route matches the named route
def self.route_matches?(req, named_route)
begin
recognized_route = Rails.application.routes.recognize_path(req.path, method: req.request_method)
recognized_route[:controller] == 'forms' && recognized_route[:action] == 'submit'
recognized_route[:controller] == 'submissions' &&
recognized_route[:action] == 'create' &&
recognized_route[:touchpoint_id].present? &&
recognized_route[:format] == 'json'
rescue ActionController::RoutingError
false
end
end

# Custom response for throttled requests
self.throttled_response = lambda do |env|
self.throttled_responder = lambda do |env|
[429, { 'Content-Type' => 'text/plain' }, ["Too many requests. Please try again later."]]
end
end

0 comments on commit 4545658

Please sign in to comment.