Error handling for HTML view (will fix repeated code at a later date)