Creating the handleError function