return proper status codes on errors