I am creating new record using "InsertAsync" using asp.net zero tool. But i am getting an error message "An internal error occurred during your request" on UI and i want to show an exact error message on UI. I tried with Try-Catch but it is not caching any error message. So how to get the exact error message from "InsertAsync".
Same issue is getting during Update and DeleteAsync
Below are my project details-
Project Details: i) Created Project Structure using Asp.Net Zero tool ii) Using Asp.Net Core iii) UI Angular-5
11 Answer(s)
-
0
There will be some logs when "An internal error occurred during your request".
Please take a look at the application's log.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
try { //db operations } catch (DbUpdateException e) { SqlException s = e.InnerException.InnerException as SqlException; //handle and see your exception }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
<cite>alper: </cite>
I tried this but not working. try { } catch (DbUpdateException e) { SqlException s = e.InnerException.InnerException as SqlException; //handle and see your exception } }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
<cite>maliming: </cite>
Hi, I want to show an exact error message on UI . I know the reason why insertion is failing but not getting any error message from InsertAsync.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Call CurrentUnitOfWork.SaveChangesAsync() to catch exceptions
try { //db operations. CurrentUnitOfWork.SaveChangesAsync() } catch (DbUpdateException e) { SqlException s = e.InnerException.InnerException as SqlException; //handle and see your exception }These are the database error messages, I think should not be displayed to the UI. The application should avoid this error. For example, do parameter verification and supplement unit testing.
Even if this kind of message is displayed to the UI, sometimes it does not understand what is going on.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
<cite>maliming: </cite> Call CurrentUnitOfWork.SaveChangesAsync() to catch exceptions
try { //db operations. CurrentUnitOfWork.SaveChangesAsync() } catch (DbUpdateException e) { SqlException s = e.InnerException.InnerException as SqlException; //handle and see your exception }These are the database error messages, I think should not be displayed to the UI. The application should avoid this error. For example, do parameter verification and supplement unit testing.
Even if this kind of message is displayed to the UI, sometimes it does not understand what is going on.
I tried but it is not working.
Actually have added the unique constraints in my database and I want to check the validation message for duplicate field. So i am trying to catch the error message and sent it to UI by editing in error message so user can easily understand.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
await CurrentUnitOfWork.SaveChangesAsync()You have to remember to add await
Still can't catch the exception?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
You should check in the application whether the field is unique in the database. ([https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero/Authorization/Users/AbpUserManager.cs#L396])) Instead of waiting for the database to return an exception message.
The database exception message is "unreadable" to the user. Non-professionals may not understand the database error message.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
If you know the exception then throw a UserFriendlyException so that users will see a dialog with an error message.
throw new UserFriendlyException("Ooppps! There is a problem!", "You are trying to see a product that is deleted...");Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
As an alternative; if you want to send all the exception messages to the clients.
Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thanks it is working.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)