Challenge 4.5: Improved View Error Handling

On the previous challenges we worked to improve our form actions on this challenge we want to improve the user experience when looking at the registries. With our current code, if an user tries to view a registry that was deleted or that is no longer available, he would only get a blank page and no details of information of what went wrong.

Fortunately this is very easy to solve, and it only requires a few minor changes to our view.phtml template. We actually already have some similar code running on our index.phtml template

Our current view.phtml template looks like this:

As you can see we are getting the currently loaded gift registry from the Magento registry, and outputting the gift registry information. The only thing we need to do know is to add a if statement to check that the registry we are loading actually exists, if ti doesn't we will show an error message.

The updated code should look as follows:

Conclusion

With very simple code we where able to improve the usability of our Magento code, when creating custom extension is important to remember to create meaningful errors and exceptions for the users.