Set proper error codes in each case