Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In example application, response returns status codes, not more full featured objects #18

Open
mooreds opened this issue Apr 21, 2020 · 1 comment

Comments

@mooreds
Copy link
Contributor

mooreds commented Apr 21, 2020

Here's the relevant section of the example code
https://github.com/FusionAuth/fusionauth-netcore-client/blob/master/fusionauth-netcore-client-test/fusionauth-netcore-client-test/test/io/fusionauth/Example.cs

  public User GetUserByEmail(string email) {
      var response = client.RetrieveUserByEmail("user@example.com");

      if (response.WasSuccessful()) {
        var user = response.successResponse.user;
        return user;
      }
      if (response.errorResponse != null) {
        // Error Handling
        var errors = response.errorResponse;
        return null;
      }
      if (response.exception != null) {
        // Exception Handling
        var exception = response.exception;
        return null;
      }
      return null;
    }

However, if you serialize the response object, you see that the status code is returned, not the exception or errorResponse objects.

using Newtonsoft.Json;
//...
string json = JsonConvert.SerializeObject(response);

If I pass the wrong API key, I get this response when I print the JSON:

{"statusCode":401}

And if I pass an email address which does not exist in my fusion auth databse, I get this message:

{"statusCode":404}

So, I'd suggest either wrapping these error codes in the error objects provided, or changing the example app code to be:

   else if (response.statusCode != 200)
            {
                // Exception Handling
                var statusCode = response.statusCode;
                return null;
            }

Here's my software versions:

FA: 1.15.5
FusionAuth.Client (from .csproj): 1.15.7
Target .NET framework: netcoreapp3.1

@tyduptyler13
Copy link
Contributor

The API error paths usually respond with status codes and exception messages. The only two statuses that don't have interesting messages are the 401 and 404. (and 500 but those shouldn't happen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants