Question: Return error code instead of message in ASP.NET Identity API

Question

Return error code instead of message in ASP.NET Identity API

Answers 0
Added at 2017-11-30 22:11
Tags
Question

I am building a ASP.NET Web API endpoint for creating managing users. This is a REST interface and I'd like to return error codes when something goes wrong. Not just the HTTP Status Codes but include my own error code in for instance a HTTP 400 BadRequest so the client would know a detailed message to display.

I know I can override the error messages in ASP.NET Identity Core, but this is not Core, so how can I return an error code instead of the string message when using UserManager to create a new user?

var identityResult = await UserManager.CreateAsync(user, model.Password)

The VS template generates a GetErrorResult method the returns a BadRequest which returns the ModelState object, but that is messages. How could use the validation logic of the UserManager but return my own error codes?

What I am really trying to achieve here is to let the client have control of the message that gets displayed by having this endpoint that creates the user simply just return an error code.

Answers to

Return error code instead of message in ASP.NET Identity API

Source Show
◀ Wstecz