From fd6a0a12b49eee23ad8d7473ef15c12cf425e0c4 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Mon, 25 Nov 2024 14:53:09 -0600 Subject: [PATCH] Synth error handling --- app/models/issue/synth_limit_exceeded.rb | 5 +++++ app/models/provider/synth.rb | 17 ++++++++++++----- app/views/issue/_synth_limit_exceeded.html.erb | 13 +++++++++++++ .../issue/synth_limit_exceededs/show.html.erb | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 app/models/issue/synth_limit_exceeded.rb create mode 100644 app/views/issue/_synth_limit_exceeded.html.erb create mode 100644 app/views/issue/synth_limit_exceededs/show.html.erb diff --git a/app/models/issue/synth_limit_exceeded.rb b/app/models/issue/synth_limit_exceeded.rb new file mode 100644 index 00000000..01a8becb --- /dev/null +++ b/app/models/issue/synth_limit_exceeded.rb @@ -0,0 +1,5 @@ +class Issue::SynthLimitExceeded < Issue + def title + "Synth API Credit Limit Exceeded" + end +end diff --git a/app/models/provider/synth.rb b/app/models/provider/synth.rb index 8247ab34..d8fde92d 100644 --- a/app/models/provider/synth.rb +++ b/app/models/provider/synth.rb @@ -194,11 +194,18 @@ class Provider::Synth end def build_error(response) - Provider::Base::ProviderError.new(<<~ERROR) - Failed to fetch data from #{self.class} - Status: #{response.status} - Body: #{response.body.inspect} - ERROR + if response.status == 402 + Provider::Base::ProviderError.new(<<~ERROR) + Your Synth API credit limit has been exceeded + Please visit your Synth billing settings to upgrade your plan or wait for your credits to reset. + ERROR + else + Provider::Base::ProviderError.new(<<~ERROR) + Failed to fetch data from #{self.class} + Status: #{response.status} + Body: #{response.body.inspect} + ERROR + end end def fetch_page(url, page, params = {}) diff --git a/app/views/issue/_synth_limit_exceeded.html.erb b/app/views/issue/_synth_limit_exceeded.html.erb new file mode 100644 index 00000000..c91922b1 --- /dev/null +++ b/app/views/issue/_synth_limit_exceeded.html.erb @@ -0,0 +1,13 @@ +
+

Your Synth API credit limit has been exceeded.

+ +

You can:

+ +
\ No newline at end of file diff --git a/app/views/issue/synth_limit_exceededs/show.html.erb b/app/views/issue/synth_limit_exceededs/show.html.erb new file mode 100644 index 00000000..6c3553f6 --- /dev/null +++ b/app/views/issue/synth_limit_exceededs/show.html.erb @@ -0,0 +1,15 @@ +<%= content_for :title, @issue.title %> + +<%= content_for :description do %> + <%= render "issue/synth_limit_exceeded" %> +<% end %> + +<%= content_for :action do %> +
+ <% if self_hosted? %> + <%= link_to "View Usage & Upgrade", "https://dashboard.synthfinance.com/settings", class: "btn btn--primary" %> + <% else %> +

Please contact the Maybe team for assistance.

+ <% end %> +
+<% end %> \ No newline at end of file