Free Support Forum - groupdocs.com

Hide error & error details


#1

Hello Team,



Is it possible, for security reasons, to hide errors and display a generic message like ’ there was a problem with rendering. Please contact us via…’?

ShowExceptionDetailsOnClient option set as false is still displaying some information about the error that has occurred (see attached).



Thank you!


#2

Hello Deric,


Thank you for the request. Yes, you can show your custom exception message. Here is a code example:

Viewer.Subscribe(new DocumentOpenSubscriber());
internal class DocumentOpenSubscriber : IEventSubscriber
{
public void HandleEvent(IEvent eventDesc)
{
myException exception;
IDocumentProcessingEvent documentEvent = (IDocumentProcessingEvent)eventDesc;
string path = documentEvent.DocumentPath;
DocumentOpeningErrorEvent errorEvent = eventDesc as DocumentOpeningErrorEvent;
if (errorEvent != null)
{
if (errorEvent.Exception != null)
{
exception = new myException(“Custom Message”, errorEvent.Exception);
}
}
}
}

public class myException : ApplicationException
{
public myException(string msg, Exception e) : base(msg, e) { }
}

For more info please check our documentation

Best regards.

#3

Hello Pavel,



Although I see error in viewer, debugging is not going through HandleEvent code that I added in Global.asax.cs:



public class DocumentOpenSubscriber : IEventSubscriber

{

public void HandleEvent(IEvent eventDesc)

{

myException exception;

IDocumentProcessingEvent documentEvent = (IDocumentProcessingEvent)eventDesc;

string path = documentEvent.DocumentPath;

DocumentOpeningErrorEvent errorEvent = eventDesc as DocumentOpeningErrorEvent;

if (errorEvent != null)

{

if (errorEvent.Exception != null)

{

exception = new myException(“Custom Message”, errorEvent.Exception);

}

}

}

}





public class myException : ApplicationException

{

public myException(string msg, Exception e) : base(msg, e) { }

}



public class MvcApplication : System.Web.HttpApplication

{

protected void Application_Start()

{

AreaRegistration.RegisterAllAreas();

Groupdocs.Web.UI.Viewer.InitRoutes();

Groupdocs.Web.UI.Viewer.SetRootStoragePath(docLocation);

Groupdocs.Web.UI.Viewer.SetLicensePath(Server.MapPath("~/Licenses/GroupDocs.Viewer.lic"));

Groupdocs.Web.UI.Viewer.EnableFileListRequestHandling(true);

Groupdocs.Web.UI.Viewer.ShowExceptionDetailsOnClient(showError);

if (!String.IsNullOrEmpty(docLog))

Groupdocs.Web.UI.Viewer.SetLogFilePath(docLog);

Groupdocs.Web.UI.Viewer.Subscribe(new DocumentOpenSubscriber());

RegisterRoutes(RouteTable.Routes);



}







Can you please help?



I am using

VS 2012,

Groupdocs.Viewer.dll v. 2.14.0.0

MVC 4

.NET v4.5

IIS 8.5


#4

Hello Deric,


Please try to move this code to the beck end (or controller if you use MVC project) of the web page with the Viewer like shown on this screenshot. As you can see the code is in the default web page beck end.

Best regards.

#5

Hello Pavel,



I have moved the code in controller, but it is still not working (https://drive.google.com/file/d/0ByZC1UqGlDWbVFZTZ05WdXVBNjg/view?usp=sharing).

Attached is displayed error from this project, when extension is not supported.

Can you please take a look how to customize this message?





Thank you!


#6

Hello Denic,


I have investigated this more deep and had conversation with our product team about it and have found next: Unfortunately at this moment the “DocumentOpeningErrorEvent” can be used only in the WinForms project. That means that in the web application you can’t change error text.

Sorry for the inconvenience.

#7

Hello Pavel,



Thank you for investigating!

Do you have any workarounds for this problem, for example to hide the error text completely from screen?

Also please let me know if this enhancement might be included in future plugin versions.


#8

Hi again,


Yes, if you will set .EnableStandardErrorHandling(false) then errors like: file not found , this file type not supported etc will not be shown, the spinner “File loading” will spin for all the time.
Only in the browser console will be failed request with error.

Best regards.

#9

Ok, I can confirm that workaround is working as you described. Thank you!


#10

Hi Denic,


Glad to hear that.

Best regards.