November Happy Hour will be moved to Thursday December 5th.

Meaning full error message from ISelectionFactory

Vote:
 

Hi,

I'm using a ISelectionFactory to generate a list of values for a property - the data for which comes from an external service.

I'd like to present a meaning error message wihtin the CMS if the service throws an exception.

I've tried the following inside my GetSelections method:

throw new EPiServerException("The service has returned no values - please raise with your administrator.");

This is close as EPiServer doesn't render the block properties and I get the familiar red icon in the top right. The problem is the message is always:

Something went wrong

  • An unexpected error occurred, please contact your system administrator

Is there anyway to present a custom message?

I tried several of the overloads but its always the above message.

#147070
Apr 05, 2016 17:20
Vote:
 

Forgive the rubbish spelling in that title!

#147071
Apr 05, 2016 17:23
Vote:
 

Implement IValidate instead on page that also checks your selection factory and shows warning?

#147084
Apr 05, 2016 22:43
Vote:
 

Thanks Daniel,

But IValidate is only used when saving a page or block - in my situation, the SelectOne property is required, so is shown as part of the Required Properties interface but if the service fails, the drop-down is unpopulated.

Rather than leave the editor with a form they now can't submit - I'd prefer to try and get a message on screen to indicate the service failure.

Cheers

#147098
Apr 06, 2016 8:14
Vote:
 

Do the results of the service change so often you need to call the service to populate the dropdown every time the page is loaded in edit mode?

If not so, I'd rather have the values for the dropdown synced from the service to Episerver (as a property somewhere) in a scheduled job as often as needed and then just read from that property instead of calling the service.

Not really an answer to your question, but it seems a bit of an overhead to call the service everytime. (Though I don't know the whole use case you are having).

To proceed with the error itself, I'd suggest you look into where the error comes from and if you can workaround it and if you can override the widget that displays the dropdown to show your custom message. This might help you with that.

BR,

Marija

#147119
Apr 06, 2016 15:16
Vote:
 

Thanks Marija

I am caching the response from the service so subsequent calls don't take the hit. I'm just trying to manage an edge case.

I'll take a look at your article.

Cheers

#147124
Apr 06, 2016 15:33
Vote:
 

Tested a little by tweaking IValidate implementation but it got too ugly in the end. Displaying by modifying the property like Marija or directly on page (just for editors) seems to be the easiest path...

#147129
Apr 06, 2016 16:22
Vote:
 

How about letting the ISelectionFactory populate the dropdown with a single row, where the value is something unique to be identified as "something went wrong".

Create a validationattribute that is added to that same property and if the value is the unique identifier from above, validate to false and let the error message be something understandable.

Here are some useful hints on validation.

#147515
Apr 17, 2016 19:52
Vote:
 

I suggest to catch the error, return a SelectItem object an with a special value e.g. -1 , and then use IValidate to check the selection value is -1 to return your custom error message (e.g. Service is not available)

#147520
Apr 18, 2016 6:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.