Dotnet
Authentication and Authorization - Login

Exercise - Exception Handling

PRO

I finished! On to the next chapter

Outline

Exercise: Exception Handling

In the Conduit.Models Project

Add a new class in the Exceptions Namespace
  • Name it LoginFailedException
  • Inherits from Exception
  • Add a constructor with a message parameter type string
  • Pass the parameter to the base class

In the Conduit.Api Project

Modify UsersController.LoginAsync Method
  • Add a try...catch block around the existing code
    • Catch an Exception
    • Log the error
    • Return a 500
  • Add a second catch block
    • Catch the LoginFailedException
    • Log the warning
    • Return a 400 or a 422

Hint: Review the RegisterUserAsync method for help implementing the try...catch block.