Fix error-catching bug; send correct status codes