{"action":"created","issue":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/283","labels_url":"https://api.github.com/repos/visionmedia/superagent/issues/283/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/superagent/issues/283/comments","events_url":"https://api.github.com/repos/visionmedia/superagent/issues/283/events","html_url":"https://github.com/visionmedia/superagent/issues/283","id":21976190,"number":283,"title":"[discuss] change how errors are handled","user":{"login":"defunctzombie","id":84792,"avatar_url":"https://avatars.githubusercontent.com/u/84792?v=3","gravatar_id":"","url":"https://api.github.com/users/defunctzombie","html_url":"https://github.com/defunctzombie","followers_url":"https://api.github.com/users/defunctzombie/followers","following_url":"https://api.github.com/users/defunctzombie/following{/other_user}","gists_url":"https://api.github.com/users/defunctzombie/gists{/gist_id}","starred_url":"https://api.github.com/users/defunctzombie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/defunctzombie/subscriptions","organizations_url":"https://api.github.com/users/defunctzombie/orgs","repos_url":"https://api.github.com/users/defunctzombie/repos","events_url":"https://api.github.com/users/defunctzombie/events{/privacy}","received_events_url":"https://api.github.com/users/defunctzombie/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":30,"created_at":"2013-11-01T18:57:54Z","updated_at":"2015-03-14T08:29:57Z","closed_at":"2015-03-09T00:56:23Z","body":"Currently errors are handled in the following ways:\r\n\r\n1. If the function to a `.get` or a `.end` as an arity of two, the first will be an error and the second a response. If it has an arity of one then only the response is provided.\r\n1. In the case of non-200 responses, no error is emitted or set and the user must check res.status\r\n\r\nI would like to discuss the following changes:\r\n\r\n1. No more magic for the callback. Always require an error argument to make things simpler and more obvious at the callsites. The returned \"request\" object from `.get` or `.end` could still emit error to allow for some \"centralize\" handling.\r\n1. All non-200 responses are treated as errors. This means that we detect the response status and make an error object with a `.status` field as needed. We do no other response processing like detecting an error message or whatever (leaving that up to the user). In the case of some network error or other xmlhttprequest error (the current error types) we don't set a `.status` since there wouldn't be one.\r\n\r\nThe above brings a few advantages in my mind (yes the changes would be major version bump breaking).\r\n\r\n* less ambiguous function calls by removing magic arity use\r\n* simpler error handling at the callsite since for ajax requests, any non `2xx` is a non-success and therefore an error. Making the code to act on success simpler in the common case (currently one has to constantly check `res.status` in the callbacks"},"comment":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/comments/80142634","html_url":"https://github.com/visionmedia/superagent/issues/283#issuecomment-80142634","issue_url":"https://api.github.com/repos/visionmedia/superagent/issues/283","id":80142634,"user":{"login":"dcousens","id":413395,"avatar_url":"https://avatars.githubusercontent.com/u/413395?v=3","gravatar_id":"","url":"https://api.github.com/users/dcousens","html_url":"https://github.com/dcousens","followers_url":"https://api.github.com/users/dcousens/followers","following_url":"https://api.github.com/users/dcousens/following{/other_user}","gists_url":"https://api.github.com/users/dcousens/gists{/gist_id}","starred_url":"https://api.github.com/users/dcousens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcousens/subscriptions","organizations_url":"https://api.github.com/users/dcousens/orgs","repos_url":"https://api.github.com/users/dcousens/repos","events_url":"https://api.github.com/users/dcousens/events{/privacy}","received_events_url":"https://api.github.com/users/dcousens/received_events","type":"User","site_admin":false},"created_at":"2015-03-14T08:29:57Z","updated_at":"2015-03-14T08:29:57Z","body":"Although I agree with @kmalakoff that only in the event of an actual exception should the `err` argument be not `null`,   I can't help but realize how much I personally would expect an error for things like a `404`, which is a valid response. \r\n\r\nThat said, I guess I'd just quickly adjust to that and enforce the expected status code everywhere."}}