In this section, we will be adding the user registration feature to our application. First of all, we have to consider some constraints for our application:
- Only one unique email address can be registered per user
- Every user must have an unique username
- Email addresses must be valid
If one of the checks fails, we have to reject the request. For the first two checks, we have to return the 409 Conflict HTTP code, while for the latest one, we have to return 400 Bad Request. API Gateway uses exceptions for status code. This means that our handler should return exceptions for every case, so we can map those exceptions to HTTP error code on the API Gateway level.
From a business logic point of view, the last requirement is easy; ...