Hide exceptions while rendering a document using viewer

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!

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.

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

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.

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!

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.

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.

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.

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

Hi Denic,


Glad to hear that.

Best regards.