Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

[DisableValidation] and [DontWrapResult] do not work in API controllers #6343


User avatar
0
deventerprise created

I'm creating a new API controller for a client to use, I want to disable the built-in error handling for bad parameters (so that I can return a 400 - Bad Request instead of a 500) and also need to prevent any results from being wrapped inside a result property.

I've tried [DisableValidation] and [DontWrapResult] on the controller as well as the controller methods but it does not seem to have any effect. How can I do this otherwise?


5 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Show code.

  • User Avatar
    0
    deventerprise created
    [Route("api/[controller]/[action]")]
    public class MyController : MyAppControllerBase
    {
            [HttpGet]
            [DontWrapResult]
            [AbpAuthorize]
            public IActionResult GetSomething()
            {
                ...
                return Ok(someData);
            }
            
            [HttpPost]
            [DisableValidation]
            [AbpAuthorize]
            public IActionResult CreateSomething([FromBody] InputDto model)
            {
                return Ok();
            }
    }
    
  • User Avatar
    0
    aaron created
    Support Team

    ABP already does not wrap IActionResult (docs).

    What are the expected and actual results?

  • User Avatar
    0
    deventerprise created

    Doesn't seem to be the case.

    From my eaxmple, if a required field on InputDto is not sent, then you get a 500 HTML page response because of the validation exception, [DisableValidation]does nothing.

    Similarly, the getter is always wrapped in { result: [{}], success: true... } type JSON even though the attribute [DontWrapResult] is applied and despite the documentation saying it won't wrap it...

  • User Avatar
    0
    ryancyq created
    Support Team

    Can you share the http response of

    • api/my/GetSomething
    • api/my/CreateSomething

    also, the error full stacktrace of 500 internal error