4

I extended Bart's Flickr ECL provider to thow an Exception() when it cannot access the third party Flickr API. This shows a nice error message in the Tridion 2013 CME GUI (see screenshot below).

Is throwing an new Exception() the best way to present an error to the user? and is there any other way to present a warning without failing?

throw new Exception(
    String.Format("Error while retrieving from Flickr; Error code {0}: {1}",
        error.AttributeValueOrDefault("code"),
        error.AttributeValueOrDefault("msg")));

enter image description here

5

There is no method build into ECL - the Tridion UI doesn't really have anything ECL could build it on top of as far as I know. An Anguilla data extender can't return a result and a warning. It can return a result or an error.

Try to avoid throwing exceptions in IContentLibrary.CreateContext. Unless you need to determine if the specific user has access to the remote server you should typically not even make any calls to the remote server here - it will slow down the UI when expanding publication nodes.

One workaround that can give some visual indication of an error without opening the error dialog would be to inject a node in the tree giving some visual feedback. So when the user expands the mountpoint node (ECL will call IContentLibraryContext.GetFolderContent), she will get a node with an error icon and for example the title "Unable to connect to the server". Any other operation (including calls to GetFolderContent for any other folder than the mountpoint folder) should throw the standard exception. To avoid someone managing to add this error node as an image somewhere I recommend using a folder item.

| improve this answer | |
  • Great idea! I implemented it in IFolderContent GetFolderContent(), so it only checks the external system when a user tries to browse the mountpoint. flickr.com/photos/25928276@N02/10205001535 – Jan H Oct 11 '13 at 10:21
  • @JanH please feel free to commit those changes to the open source code of the Flickr ECL provider, that sounds like a useful addition. – Bart Koopman Oct 11 '13 at 11:24
  • @BartKoopman it's a screenshot, not completely implemented. My mountpoint always returns this error folder when the CM asks for the root contents ;) I will see if I can wrap up the code and commit. – Jan H Oct 11 '13 at 19:18
  • Changes for both Error item in mountpoint and throwing an exception are committed. See code.google.com/p/sdl-tridion-world/source/detail?r=54 – Jan H Oct 23 '13 at 11:49
4

Additionally to Lars's answer, raising an error can indeed simply be done by throw new Exception(), there are no custom exceptions available in the ECL API that you can use.

I would use the override Exception(message, innerException) if you have an Exception available, and for the message you could use a resource, like I have done here in the class implementing the IContentLibrary interface:

public void Initialize(string mountPointId, string configurationXmlElement, IHostServices hostServices)
{
    try
    {
        // do something to initialize your provider 
        // like reading the mountpoint configuration
    }
    catch (Exception e)
    {
        // just raise the error with a readable message
        throw new Exception(string.Format(Resources.ConfigurationError, mountPointId), e);
    }
}

But as Lars mentions, I have to agree it would probably be nicer to do this check in your class which implements the IContentLibraryContext interface.

But keep in mind, while it is nice to show a visual indication to a user that the connection cannot be made for some reason, not everything has a use for this visual representation. When the publisher is trying to render an ECL item, it needs an error to halt the publishing process.

| improve this answer | |
  • 1
    If something is not right at publishing time there is indeed no other option then throwing an error, or fail silently. Lars's suggestion is great for helpful messages to the user. By using the folder type EclItemTypes.Folder, and a custom subtype "error" we can prevent any other automated system for mistaken the error message for a real folder. – Jan H Oct 11 '13 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.