Skip to content

Custom exceptions for authentication / authorization issues #94

@irby

Description

@irby

Is your feature request related to a problem? Please describe.

I would like to see custom exceptions returned in various cases such as login failure, variable access failure, etc., to help me, as a developer, handle various edge cases.

With the blanket HttpRequestException, until I inspect the error message I don't know what issue I've hit, thus it makes it more difficult for me to handle that case properly and relay the correct error message to the user.

Describe the solution you would like

I would like custom exceptions to be publicly available to be thrown for various cases:

  • ConjurAuthenticationException to be thrown when LogIn / LogInAsync fails due to authentication error
  • ConjurNotFoundException to be thrown when accessing a resource that does not exist or user does not have access to

These are just examples and not a complete list of all exception cases to be considered.

Describe alternatives you have considered

The current status quo right now is that if there's any issue with login / variable access that each case throws an HttpRequestException. In order to determine the failure, we must inspect the error message and determine what the issue is, which is not very user friendly.

Additional context

When login fails, this is the exception we get:

Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Conjur.Extensions.ReadAsync(Task`1 responseTask, CancellationToken cancellationToken)
   at Conjur.Client.LogInAsync(NetworkCredential credential, CancellationToken cancellationToken)
   at Program.Run() in /Users/mirby/source/testbed/conjur/conjur-sdk/ConjurSDKTestNet8/ConjurSDKTestNet8/Program.cs:line 25
   at Program.Main(String[] args) in /Users/mirby/source/testbed/conjur/conjur-sdk/ConjurSDKTestNet8/ConjurSDKTestNet8/Program.cs:line 9

When the resource does not exist or context does not have permission to access, this is the exception we get:`

Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Conjur.Resource.CheckAsync(String privilege, CancellationToken cancellationToken)
   at Program.Run() in /Users/mirby/source/testbed/conjur/conjur-sdk/ConjurSDKTestNet8/ConjurSDKTestNet8/Program.cs:line 34
   at Program.Main(String[] args) in /Users/mirby/source/testbed/conjur/conjur-sdk/ConjurSDKTestNet8/ConjurSDKTestNet8/Program.cs:line 9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions