refactor displayErrorMessage funcion

eliminate if else block