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)
-
0
Show code.
-
0
[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(); } }
-
0
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... -
0
Can you share the http response of
api/my/GetSomething
api/my/CreateSomething
also, the error full stacktrace of 500 internal error