Ejemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] User user)
        {
            try
            {
                var responseOnRegister = await _handler.Register(user);

                return(StatusCode(StatusCodes.Status201Created, responseOnRegister.ToString()));
            }
            catch (Exception e)
            {
                if (e is MongoDB.Driver.MongoWriteException)
                {
                    return(BadRequest(new ErrorResponse(error: Text.EmailUsed).ToString()));
                }
                if (e is ServerException)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: Text.ServerException, errorMessage: e.ToString()).ToString()));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: Text.InternalServerError, errorMessage: e.ToString()).ToString()));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register([FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                //TODO: use FluentValidation
                return(BadRequest(new ErrorResponse(error: ModelState.Values.ToString())));
            }
            try
            {
                var responseOnRegister = await _handler.Register(user);

                return(StatusCode(StatusCodes.Status201Created, responseOnRegister.ToString()));
            }
            catch (MongoDB.Driver.MongoWriteException)
            {
                return(BadRequest(new ErrorResponse(error: "Email used").ToString()));
            }
            catch (ServerException e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(error: "Internal server error", errorMessage: e.ToString()).ToString()));
            }
            //TODO: Add general exception
        }