Set right error code, when a problem occurs