Changing Httpcode status
See original GitHub issueHi, I want to have different HttpCodeStatus inside my AppService. For now all I can return are the HttpCode set by the AddFilters method that’s called inside the AddAbp. So only these filters
private static void AddFilters(MvcOptions options)
{
options.Filters.AddService(typeof(AbpAuthorizationFilter));
options.Filters.AddService(typeof(AbpAuditActionFilter));
options.Filters.AddService(typeof(AbpValidationActionFilter));
options.Filters.AddService(typeof(AbpUowActionFilter));
options.Filters.AddService(typeof(AbpExceptionFilter));
options.Filters.AddService(typeof(AbpResultFilter));
}
Here what im looking to modify is the AbpExceptionFilter. Because i want to be able to send other type of exception then those one define by the GetSatuscode of the abpExceptionFilter:
protected virtual int GetStatusCode(ExceptionContext context)
{
if (context.Exception is AbpAuthorizationException)
{
return context.HttpContext.User.Identity.IsAuthenticated
? (int)HttpStatusCode.Forbidden
: (int)HttpStatusCode.Unauthorized;
}
if (context.Exception is AbpValidationException)
{
return (int)HttpStatusCode.BadRequest;
}
if (context.Exception is EntityNotFoundException)
{
return (int)HttpStatusCode.NotFound;
}
return (int)HttpStatusCode.InternalServerError;
}
}
How can i do so?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Can we change the status code of a HTTP request?
Can we change the status code of a HTTP request? · Enable SSL Proxying for testing domains · Right click URL → Select...
Read more >Change the HTTP Status Code of a REST API
To set a different HTTP Status Code in the Response, do the following: Go to Manage Dependencies... and add the SetStatusCode action of...
Read more >Is it acceptable to modify the text sent with the HTTP status ...
The status messages (technically called "reason phrases") are only recommendations and "MAY be changed without affecting the protocol).".
Read more >Solved: Change and Set the HTTP status code Response
I want to set HTTP status code based on my backend service response. Though my backend service is failed some reason(Say Ex:Invalid Request)...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Set its order:
try using the following code:
add code into
PreInitialize
method of xxxModule, replace IExceptionFilter service,