Base solution for your next web application
Open Closed

ABP Exception #50


User avatar
0
cosmic created

Hi, I have this code in the MVC controller:

public async Task<ActionResult> Edit(long? id)
{
    if (id == null)
    {
        throw new UserFriendlyException("Bad request");
    }

    var output = await _userAppService.GetAsync(new GetUserInput(id.Value));

    if (output.User == null)
    {
        throw new UserFriendlyException(L("InvalidUser"));
    }

    return View(output.User.MapTo<UserEditViewModel>());
}

If the ID is not supplied, then it will throw an UserFriendlyException, this is correct. But, when I look into the log file, there is following exception:

2015-04-17 13:43:06.1042|ERROR|Default|Abp.UI.UserFriendlyException: Bad request
   at Controllers.UsersController.<Edit>d__f.MoveNext() in c:\...\Controllers\UsersController.cs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task)
   at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

It looks like a result of unhandled exception. I think, the UserFriendlyException (AbpException) is not handled correctly. In log file should be only first line, or am I wrong?


6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Can you check if customErrors mode is on in your web.config as shown here:

    <customErrors mode="On" />
    
  • User Avatar
    0
    cosmic created

    Yes, customErrors is set On. It was a first thing I changed.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I think there is a problem with async actions. I did not implement for async. See the issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/386">https://github.com/aspnetboilerplate/as ... issues/386</a> It will be fixed soon. You can write your codes as it's working.

    Thanks.

  • User Avatar
    0
    cosmic created

    Hi, I changed this method to "normal" sync method and I tested it again. But, the error is the same. I think this is not only problem of an async implementation, there may be a global problem (somewhere deeper in the ABP framework code) to catch exceptions right way.

    I'm using Multi Page Application, not Angular, Durandal, etc. Please test this example and you should get the same result.

    Thank you.

    By the way, this framework is great, it saved me a lot of time, I appreciate all of your work, keep going...

  • User Avatar
    0
    hikalkan created
    Support Team

    Thanks for informing. I added this to the issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/386">https://github.com/aspnetboilerplate/as ... issues/386</a>

  • User Avatar
    0
    hikalkan created
    Support Team

    Actually, ABP writes full stack of exception even if UserFriendlyException. But you're right, it's better to hide it. Indeed, someone will want detailed exception. Maybe it's better to write single-line warning and all stack trace as debug.