Replaced undefined variable $error by message got from exception object

Replace undefined variable $error by message got from exception object