Update API error handling to use HTTP status codes