Hi,
We want to throw some user defined errors from controller now we were using throw User friendly Exception for showing Errors it works in services but it not perfect in Controller. if we throw errors from controller it just work less. so how we can throw errors from controller expect a possible guidance from you.
Currently used This: throw new UserFriendlyException(L("CloumnNameMustbeSameDownloadTemplateFileforReference"));
Thanks...
8 Answer(s)
-
0
Hi,
I couldn't understand what's the problem with throwing UserFriendlyException in a Controller. Isn't it working at all or are there bugs in special cases?
-
0
Hi,
how to throw errors from(Asp MVC) controller to Angularjs controller while uploading a file. User friendly Exception is not working in file uploading case i need an explanation about this.
Thanks.
-
0
OK, now understood. I created an issue about this: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/issues/58">https://github.com/aspnetzero/aspnet-zero/issues/58</a> I will resolve it in v1.6.1. I hope it's not critical for you and you can wait for a while. Thanks.
-
0
Hi,
But it's most important for me. because we could not identified what are the issues arise in controller. can i get any other alternative way for solve this..for resolving this only i will move to forward. kindly give a possible solution.
Thanks...
-
0
I'm having the same problem, is this resolved?
-
0
Hi,
This was related to AspNet Zero (<a class="postlink" href="http://www.aspnetzero.com/">http://www.aspnetzero.com/</a>) and resolved. Do you have similar problem? Can you sahre your controller action?
-
0
Hi! sure
// GET: FileUploader public async virtual Task<JsonResult> Index() { string output; try { int teste = Request.Files.Count; CreateUpdateImovelByPortfolioInput dto = new CreateUpdateImovelByPortfolioInput(); dto.PortfolioId = Convert.ToInt16(Request.Params.Get("portfolioId")); using (ZipArchive archive = ZipFile.OpenRead(@"C:\sd.zip")) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) { using (MemoryStream ms = new MemoryStream()) { entry.Open().CopyTo(ms); //etc } } } } output= await _service.Create(dto); } catch(Exception o) { throw new UserFriendlyException(o.ToString()); } return Json(new { Data = output }); }
-
0
Hi,
OK, understood it. You are probably using a 3rd party ajax file upload library which does not handle ABP's responses. You have two options:
- Add [DontWrapResult] attribute to your Index action, so ABP does not wrap/change your return value. And return a proper object which is understood by your library instead of throwing exceptions. UserFriendlyException does not work in this case.
- This depends on your library. I used angular file upload (<a class="postlink" href="https://github.com/nervgh/angular-file-upload">https://github.com/nervgh/angular-file-upload</a>) and handled errors on onSuccessItem as shown below:
vm.uploader.onSuccessItem = function (fileItem, response, status, headers) { $uibModalInstance.close(); if (response.success) { //... } else { abp.message.error(response.error.message); } };
Note: Be sure that you're using the latest Abp.* packages.