Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Handle invalid API key (#1515)

Nikhil Badyal13bec4599fc9
diff --git a/app/models/family.rb b/app/models/family.rb
index 999e268a..bae32843 100644
--- a/app/models/family.rb
+++ b/app/models/family.rb
@@ -159,7 +159,11 @@ class Family < ApplicationRecord
end
def synth_overage?
- self.class.synth_provider && self.class.synth_provider.usage.utilization >= 100
+ self.class.synth_provider&.usage&.utilization.to_i >= 100
+ end
+
+ def synth_valid?
+ self.class.synth_provider&.healthy?
end
def subscribed?
diff --git a/app/views/pages/dashboard.html.erb b/app/views/pages/dashboard.html.erb
index a2e5c66b..06a9115e 100644
--- a/app/views/pages/dashboard.html.erb
+++ b/app/views/pages/dashboard.html.erb
@@ -1,8 +1,14 @@
<div class="space-y-4">
- <% if self_hosted? && Current.family&.synth_overage? %>
- <div class="bg-yellow-100 border border-yellow-400 text-yellow-700 px-4 py-3 rounded relative" role="alert">
- Your Synth API credit limit has been exceeded. Please visit your <a href="https://dashboard.synthfinance.com/settings" class="font-medium underline hover:text-yellow-900">Synth billing settings</a> to upgrade your plan or wait for your credits to reset.
- </div>
+ <% if self_hosted? %>
+ <% if Current.family&.synth_overage? %>
+ <div class="bg-yellow-100 border border-yellow-400 text-yellow-700 px-4 py-3 rounded relative" role="alert">
+ Your Synth API credit limit has been exceeded. Please visit your <a href="https://dashboard.synthfinance.com/settings" class="font-medium underline hover:text-yellow-900">Synth billing settings</a> to upgrade your plan or wait for your credits to reset.
+ </div>
+ <% elsif !Current.family&.synth_valid? %>
+ <div class="bg-yellow-100 border border-yellow-400 text-yellow-700 px-4 py-3 rounded relative" role="alert">
+ Your Synth API Key is invalid. Please visit your <a href="https://dashboard.synthfinance.com/dashboard" class="font-medium underline hover:text-yellow-900">Synth dashboard</a> and verify that your API key is correct.
+ </div>
+ <% end %>
<% end %>
<header class="flex items-center justify-between">
<div>