0
ofir1234 created
Hi. I'm working with your Dynamic Web API Layer and it's very useful, but I want to understand how can I throw an error to the web client.
I have a client request, defined this way :
abp.services.app.trends.deleteSavedQuery($scope.loadQuerySelectedId)
.done(function (result) {
abp.message.info("Saved query deleted successfully");
});
//here I want to catch an error (you can't delete a query that wasn't written by you)
The service code in the server is something like this :
[HttpGet]
public void DeleteSavedQuery(int queryId)
{
if (_userManager.AbpSession.UserId == getQueryId(queryId))
{
_savedQueriesRepo.Delete(queryId);
}
else
{
//Here I want to throw an unauthorized error (403) with a message : 'you can't delete a query that wasn't written by you'
}
}
How can I throw this error from the server and catch it nicely in the client, doing it the best and conventional 'ASP.NET Boilerplate' way ?
Thanks.
4 Answer(s)
-
0
-
0
just throw UserFriendlyException and ABP will handle the rest.
-
0
I understand. Nice. One question - how can I tell the client it's a 500 or 400 or 404 server exception this way?
-
0
No way for now. Because, application layer is web independent, but these error codes are HTTP related. But we will work on this to find an elegant way.