Return proper error code