Silkey-Team / ruby-sdk

Silkey SDK for ruby
MIT License
0 stars 0 forks source link

Error Handling #8

Open angusmcleod opened 3 years ago

angusmcleod commented 3 years ago

I had a little trouble with getting the sdk to get the Silkey public key

Silkey::SDK.fetch_silkey_public_key

As I wasn't using an appropriate config (see other issue). The failure to fetch the key was triggering a redirect of the POST callback to the root path / from within the gem (which fails in discourse as that POST route doesn't exist).

There isn't a simple way to handle that type of eventuality from within the plugin. Ideally I'd like to be able to do something like this

begin
    Silkey::SDK.token_payload_verifier(token, Silkey::SDK.fetch_silkey_public_key)
rescue Silkey::AuthError, Silkey::BlahError => e
   ## handle
end

I can help you implement that, but just thought I'd get your initial thinking on this subject, i.e. error handling.

DZariusz commented 3 years ago

Idea with dedicated errors sound good as long as we do not end up with 20 different types of errors :) I have no environment where I can use this plugin myself, so I will rely on your experience as programmer here. If you could help eg. open PR (or in any other way) and improve the code in a way that you think it's better for you to handle then of course feel free to do it. Otherwise I will try to handle this later.