{"action":"opened","issue":{"url":"https://api.github.com/repos/danswater/sequielize/issues/2","labels_url":"https://api.github.com/repos/danswater/sequielize/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/danswater/sequielize/issues/2/comments","events_url":"https://api.github.com/repos/danswater/sequielize/issues/2/events","html_url":"https://github.com/danswater/sequielize/issues/2","id":99960544,"number":2,"title":"Add status code as argument in Send.success","user":{"login":"danswater","id":5284272,"avatar_url":"https://avatars.githubusercontent.com/u/5284272?v=3","gravatar_id":"","url":"https://api.github.com/users/danswater","html_url":"https://github.com/danswater","followers_url":"https://api.github.com/users/danswater/followers","following_url":"https://api.github.com/users/danswater/following{/other_user}","gists_url":"https://api.github.com/users/danswater/gists{/gist_id}","starred_url":"https://api.github.com/users/danswater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danswater/subscriptions","organizations_url":"https://api.github.com/users/danswater/orgs","repos_url":"https://api.github.com/users/danswater/repos","events_url":"https://api.github.com/users/danswater/events{/privacy}","received_events_url":"https://api.github.com/users/danswater/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-10T03:11:32Z","updated_at":"2015-08-10T03:11:32Z","closed_at":null,"body":"So this is what I have on how to implement sending a 404 status code.\r\nThis implementation resides in the gateway.\r\nhttps://gist.github.com/danswater/a25a276d839e6d2f4e3c#file-snippet-js-L15-L26\r\n\r\nBut in my opinion it would be better if we can put this in service. The only problem right now is that send.success does not support accepting status code as argument\r\nhttps://gist.github.com/danswater/2c6108f415842db41d0a#file-snippet-2-js-L6\r\n\r\nLike for example, let say this is the send.error implementation\r\n```` javascript\r\n     Send.prototype.error = function ( errorMessage, error, code ) {\r\n        this.errorMessage = errorMessage;\r\n        this.error        = error;\r\n        this.code         = code;\r\n        return this.done();\r\n    };\r\n````\r\n\r\nWe could say that the the Send object is to injected to the callback of lapin\r\n```` javascript\r\n     rabbit.respond( 'v1.legacy-content.getById', function ( data, send ) {\r\n                                                                   ^\r\n    } );\r\n````\r\n\r\nAnd then let say send.success can be refactor to support status code as argument\r\n```` javascript\r\n    SendMock.prototype.success = function ( data, code ) {\r\n        this.response = data;\r\n        this.code     = code;\r\n        return this.done();\r\n    };\r\n````\r\n\r\nSo, in the service part of the code we can now implement it like this\r\n```` javascript\r\n    Content.find( options ).then( function ( content ) {\r\n    \r\n        var returnData = ( content && content.dataValues ) || null;\r\n        if ( !returnData ) {\r\n          return send.success( returnData, 404 ); // status code are encapsulated in send object\r\n        }\r\n        send.success( returnData );\r\n    \r\n    } ).catch( function handleError ( error ) {\r\n    \r\n        send.error( error.message, null, 500 ); // status code are encapsulated in send object\r\n    \r\n    } );\r\n````\r\n\r\nThen for the implementation in the gateway\r\n```` javascript\r\n    return lapin.request( 'v1.legacy-content.getById', request.params.contentId, function ( error, data ) {\r\n    \r\n        if ( error ) {\r\n            return reply( error ).code( err.code ); // err.code === 500\r\n        }\r\n    \r\n        reply( data.data ).code( data.code ); // err.code === 200 or 404 if null\r\n    \r\n    } );\r\n````\r\n\r\nI would like to ask your feedback and the opinion on both snippets."}}