{"action":"created","issue":{"url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/406","repository_url":"https://api.github.com/repos/apigee-127/swagger-tools","labels_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/406/labels{/name}","comments_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/406/comments","events_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/406/events","html_url":"https://github.com/apigee-127/swagger-tools/issues/406","id":164642954,"number":406,"title":"Where is the err.message created in an custom OAuth handler displayed in the eventual response?","user":{"login":"reselbob","id":1110569,"avatar_url":"https://avatars.githubusercontent.com/u/1110569?v=3","gravatar_id":"","url":"https://api.github.com/users/reselbob","html_url":"https://github.com/reselbob","followers_url":"https://api.github.com/users/reselbob/followers","following_url":"https://api.github.com/users/reselbob/following{/other_user}","gists_url":"https://api.github.com/users/reselbob/gists{/gist_id}","starred_url":"https://api.github.com/users/reselbob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reselbob/subscriptions","organizations_url":"https://api.github.com/users/reselbob/orgs","repos_url":"https://api.github.com/users/reselbob/repos","events_url":"https://api.github.com/users/reselbob/events{/privacy}","received_events_url":"https://api.github.com/users/reselbob/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-09T01:29:38Z","updated_at":"2016-07-09T17:32:16Z","closed_at":null,"body":"Hi;\r\n\r\nI am writing a handler for Swagger Security. I pass the handler function definition in as part of the middleware initialization.\r\n\r\n```javascript\r\nvar oauthHandler = require(\"./handlers/oauthHandler\");\r\n\r\nvar options = {\r\n  swaggerUi: './api/swagger.json',\r\n  controllers: './controllers',\r\n  oauth:oauthHandler.handler,\r\n  useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)\r\n};\r\n\r\napp.use(middleware.swaggerSecurity(options));\r\n```\r\n\r\nThe OAuth handler checks to make sure a good token is present. If not, an ``err`` object is created as specified in the documentation.\r\n\r\n```javascript\r\n.\r\n.\r\n.\r\n    var reply = getTokenSync(request.headers);\r\n    if (!reply.token) {\r\n        var err = {};\r\n        err.message = reply.message;\r\n        err.state = null;\r\n        err.code = reply.statusCode;\r\n        err.statusCode = reply.statusCode;\r\n        err.headers = request.headers;// yeah, this needs to be cleaned up\r\n\r\n        callback(err); \r\n        return;\r\n    } \r\n```\r\n\r\nHowever, the custom message I create never makes it back anywhere in the ``response``. Either I am doing something terribly wrong, for which I apologize and welcome correction. Or as the err object gets passed on through the middleware it gets transformed. In addition, the ``response.headers`` get transformed too. Lastly, when the`` response`` makes it out of the server, ``response.body`` is an empty object.\r\n\r\nTell me please, where is my custom error message in the ``response`` emitted from the server? Do I need to do anything special to get the message to display in the sent ``response``? Better yet, is there anyway I can tell the middleware to embed the ``err.message`` in the response.body?\r\n\r\nThanks in advance.\r\n\r\nI know that must be a pretty elementary inquiry. But, my sense of professionalism requires me to give those using my API more than a sole 401 statusCode. "},"comment":{"url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/comments/231545902","html_url":"https://github.com/apigee-127/swagger-tools/issues/406#issuecomment-231545902","issue_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/406","id":231545902,"user":{"login":"whitlockjc","id":98899,"avatar_url":"https://avatars.githubusercontent.com/u/98899?v=3","gravatar_id":"","url":"https://api.github.com/users/whitlockjc","html_url":"https://github.com/whitlockjc","followers_url":"https://api.github.com/users/whitlockjc/followers","following_url":"https://api.github.com/users/whitlockjc/following{/other_user}","gists_url":"https://api.github.com/users/whitlockjc/gists{/gist_id}","starred_url":"https://api.github.com/users/whitlockjc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitlockjc/subscriptions","organizations_url":"https://api.github.com/users/whitlockjc/orgs","repos_url":"https://api.github.com/users/whitlockjc/repos","events_url":"https://api.github.com/users/whitlockjc/events{/privacy}","received_events_url":"https://api.github.com/users/whitlockjc/received_events","type":"User","site_admin":false},"created_at":"2016-07-09T17:32:16Z","updated_at":"2016-07-09T17:32:16Z","body":"You could create an error hander middleware to identify your OAuth errors and update the response accordingly.  That's what I'd do.  As for where in the swagger-tools middleware the `err.message` is overridden/set, I don't see anything.  I didn't write the security middleware so I'd have to dive deeper if the suggested approach isn't good enough."}}
{"actor":{"display_login":"whitlockjc"}}