{"action":"created","comment":{"url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/comments/24668079","id":24668079,"diff_hunk":"@@ -320,6 +331,81 @@ createHandler = function createHandler(options) {\n   }\n };\n \n+/**\n+ * Maintenance middleware\n+ * \n+ * @param {object} [options]\n+ *\n+ * @param {function} [options.status] - Returns Boolean to indicate\n+ * the application is in maintenance mode. Default reads \n+ * ERR_HANDLER_MAINT_ENABLED environment variable - Value must be\n+ * 'TRUE' to indicate an active maintenance condition, any other value \n+ * is false.\n+ *\n+ * @param {function} [options.retryAfter] - Returns\n+ * Number or String value for Retry-After response header.\n+ * Default reads ERR_HANDLER_MAINT_RETRYAFTER environment variable -\n+ * Value must be a positive integer for retry after relative seconds,\n+ * or an HTTP-date in GMT to indicate an absolte retry after period.\n+ *\n+ * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4\n+ * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37\n+ */\n+createHandler.maintenance = function maintenance(options) {\n+  options = options || {};\n+\n+  var\n+    status = typeof options.status === 'function' ?\n+      options.status :\n+      function status () {\n+        return ('' + process.env.ERR_HANDLER_MAINT_ENABLED)\n+          .trim().toLowerCase() === 'true';\n+      },\n+\n+    retryAfter = typeof options.retryAfter === 'function' ?\n+      options.retryAfter :\n+      function retryAfter() {\n+        var result,\n+            value = ('' + process.env.ERR_HANDLER_MAINT_RETRYAFTER).trim();\n+        // fallback b/c user wants maintenance & no Retry-After means 500\n+        var fallback = 3600;\n+        // First, try seconds\n+        result = parseInt(value, 10);\n+        result = (result === 0 || (result && result < 0)) ? fallback : result;\n+        if (!result) {\n+          // NaN, try date\n+          result = Date.parse(value) && value || fallback;\n+        }\n+        return result;\n+      };\n+\n+  // Expose maintenance utility to errorHandler\n+  createHandler.maintenance._isMaintenance = ","path":"error-handler.js","position":91,"original_position":91,"commit_id":"b90babea3ce84c8eb97fd56aa8404b67d62dc208","original_commit_id":"b90babea3ce84c8eb97fd56aa8404b67d62dc208","user":{"login":"localnerve","id":2454740,"avatar_url":"https://avatars.githubusercontent.com/u/2454740?v=3","gravatar_id":"","url":"https://api.github.com/users/localnerve","html_url":"https://github.com/localnerve","followers_url":"https://api.github.com/users/localnerve/followers","following_url":"https://api.github.com/users/localnerve/following{/other_user}","gists_url":"https://api.github.com/users/localnerve/gists{/gist_id}","starred_url":"https://api.github.com/users/localnerve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/localnerve/subscriptions","organizations_url":"https://api.github.com/users/localnerve/orgs","repos_url":"https://api.github.com/users/localnerve/repos","events_url":"https://api.github.com/users/localnerve/events{/privacy}","received_events_url":"https://api.github.com/users/localnerve/received_events","type":"User","site_admin":false},"body":"I see now, Gotcha :-)","created_at":"2015-02-13T14:47:31Z","updated_at":"2015-02-13T14:47:31Z","html_url":"https://github.com/ericelliott/express-error-handler/pull/10#discussion_r24668079","pull_request_url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/comments/24668079"},"html":{"href":"https://github.com/ericelliott/express-error-handler/pull/10#discussion_r24668079"},"pull_request":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10","id":28892176,"html_url":"https://github.com/ericelliott/express-error-handler/pull/10","diff_url":"https://github.com/ericelliott/express-error-handler/pull/10.diff","patch_url":"https://github.com/ericelliott/express-error-handler/pull/10.patch","issue_url":"https://api.github.com/repos/ericelliott/express-error-handler/issues/10","number":10,"state":"open","locked":false,"title":"Allow Application Maintenance Mode Using 503 Response","user":{"login":"localnerve","id":2454740,"avatar_url":"https://avatars.githubusercontent.com/u/2454740?v=3","gravatar_id":"","url":"https://api.github.com/users/localnerve","html_url":"https://github.com/localnerve","followers_url":"https://api.github.com/users/localnerve/followers","following_url":"https://api.github.com/users/localnerve/following{/other_user}","gists_url":"https://api.github.com/users/localnerve/gists{/gist_id}","starred_url":"https://api.github.com/users/localnerve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/localnerve/subscriptions","organizations_url":"https://api.github.com/users/localnerve/orgs","repos_url":"https://api.github.com/users/localnerve/repos","events_url":"https://api.github.com/users/localnerve/events{/privacy}","received_events_url":"https://api.github.com/users/localnerve/received_events","type":"User","site_admin":false},"body":"First, thanks for this tool, it's very useful.\r\n\r\nFor apps that would like to set a temporary maintenance condition, it would be really handy to be able to set a 503 maintenance response and not have to disagree with the default handling of 500+ responses by this tool. In the temporary maintenance condition, you don't want the app to shutdown, but rather to serve the 503 maintenance response and remain in that state until you've completed maintenance.\r\n\r\nHere's a PR of a fork that I'm using to deal with this in one of my apps. Integrating with this lib is a very clean solution for this. I've included tests, updated readme, and a detailed example that shows how to use the maintenance option with the environment to enter/exit the temporary maintenance condition.\r\n\r\nI also found a problem where the http error status was not being set when not using the `renderDefault`. In my case, it was when serving static 404.html, 503.html. In those instances, the resource would be served with an http response of 200. So I added a one-liner to always set a representative error status (which can be overwritten in later processing paths as the current code does).\r\n\r\nLet me know what you think.\r\nThanks,\r\nAlex","created_at":"2015-02-09T02:03:34Z","updated_at":"2015-02-13T14:47:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"197cdb2fc7af8e9b42854055692545b793cbeb60","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10/commits","review_comments_url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10/comments","review_comment_url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ericelliott/express-error-handler/issues/10/comments","statuses_url":"https://api.github.com/repos/ericelliott/express-error-handler/statuses/b90babea3ce84c8eb97fd56aa8404b67d62dc208","head":{"label":"localnerve:master","ref":"master","sha":"b90babea3ce84c8eb97fd56aa8404b67d62dc208","user":{"login":"localnerve","id":2454740,"avatar_url":"https://avatars.githubusercontent.com/u/2454740?v=3","gravatar_id":"","url":"https://api.github.com/users/localnerve","html_url":"https://github.com/localnerve","followers_url":"https://api.github.com/users/localnerve/followers","following_url":"https://api.github.com/users/localnerve/following{/other_user}","gists_url":"https://api.github.com/users/localnerve/gists{/gist_id}","starred_url":"https://api.github.com/users/localnerve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/localnerve/subscriptions","organizations_url":"https://api.github.com/users/localnerve/orgs","repos_url":"https://api.github.com/users/localnerve/repos","events_url":"https://api.github.com/users/localnerve/events{/privacy}","received_events_url":"https://api.github.com/users/localnerve/received_events","type":"User","site_admin":false},"repo":{"id":30482018,"name":"express-error-handler","full_name":"localnerve/express-error-handler","owner":{"login":"localnerve","id":2454740,"avatar_url":"https://avatars.githubusercontent.com/u/2454740?v=3","gravatar_id":"","url":"https://api.github.com/users/localnerve","html_url":"https://github.com/localnerve","followers_url":"https://api.github.com/users/localnerve/followers","following_url":"https://api.github.com/users/localnerve/following{/other_user}","gists_url":"https://api.github.com/users/localnerve/gists{/gist_id}","starred_url":"https://api.github.com/users/localnerve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/localnerve/subscriptions","organizations_url":"https://api.github.com/users/localnerve/orgs","repos_url":"https://api.github.com/users/localnerve/repos","events_url":"https://api.github.com/users/localnerve/events{/privacy}","received_events_url":"https://api.github.com/users/localnerve/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/localnerve/express-error-handler","description":"A graceful error handler for Express and Restify applications.","fork":true,"url":"https://api.github.com/repos/localnerve/express-error-handler","forks_url":"https://api.github.com/repos/localnerve/express-error-handler/forks","keys_url":"https://api.github.com/repos/localnerve/express-error-handler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/localnerve/express-error-handler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/localnerve/express-error-handler/teams","hooks_url":"https://api.github.com/repos/localnerve/express-error-handler/hooks","issue_events_url":"https://api.github.com/repos/localnerve/express-error-handler/issues/events{/number}","events_url":"https://api.github.com/repos/localnerve/express-error-handler/events","assignees_url":"https://api.github.com/repos/localnerve/express-error-handler/assignees{/user}","branches_url":"https://api.github.com/repos/localnerve/express-error-handler/branches{/branch}","tags_url":"https://api.github.com/repos/localnerve/express-error-handler/tags","blobs_url":"https://api.github.com/repos/localnerve/express-error-handler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/localnerve/express-error-handler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/localnerve/express-error-handler/git/refs{/sha}","trees_url":"https://api.github.com/repos/localnerve/express-error-handler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/localnerve/express-error-handler/statuses/{sha}","languages_url":"https://api.github.com/repos/localnerve/express-error-handler/languages","stargazers_url":"https://api.github.com/repos/localnerve/express-error-handler/stargazers","contributors_url":"https://api.github.com/repos/localnerve/express-error-handler/contributors","subscribers_url":"https://api.github.com/repos/localnerve/express-error-handler/subscribers","subscription_url":"https://api.github.com/repos/localnerve/express-error-handler/subscription","commits_url":"https://api.github.com/repos/localnerve/express-error-handler/commits{/sha}","git_commits_url":"https://api.github.com/repos/localnerve/express-error-handler/git/commits{/sha}","comments_url":"https://api.github.com/repos/localnerve/express-error-handler/comments{/number}","issue_comment_url":"https://api.github.com/repos/localnerve/express-error-handler/issues/comments/{number}","contents_url":"https://api.github.com/repos/localnerve/express-error-handler/contents/{+path}","compare_url":"https://api.github.com/repos/localnerve/express-error-handler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/localnerve/express-error-handler/merges","archive_url":"https://api.github.com/repos/localnerve/express-error-handler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/localnerve/express-error-handler/downloads","issues_url":"https://api.github.com/repos/localnerve/express-error-handler/issues{/number}","pulls_url":"https://api.github.com/repos/localnerve/express-error-handler/pulls{/number}","milestones_url":"https://api.github.com/repos/localnerve/express-error-handler/milestones{/number}","notifications_url":"https://api.github.com/repos/localnerve/express-error-handler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/localnerve/express-error-handler/labels{/name}","releases_url":"https://api.github.com/repos/localnerve/express-error-handler/releases{/id}","created_at":"2015-02-08T05:31:48Z","updated_at":"2015-02-12T17:55:57Z","pushed_at":"2015-02-12T17:55:57Z","git_url":"git://github.com/localnerve/express-error-handler.git","ssh_url":"git@github.com:localnerve/express-error-handler.git","clone_url":"https://github.com/localnerve/express-error-handler.git","svn_url":"https://github.com/localnerve/express-error-handler","homepage":"","size":130,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ericelliott:master","ref":"master","sha":"bb8de301f53b97744013effc2ad207a1add9e7a6","user":{"login":"ericelliott","id":364727,"avatar_url":"https://avatars.githubusercontent.com/u/364727?v=3","gravatar_id":"","url":"https://api.github.com/users/ericelliott","html_url":"https://github.com/ericelliott","followers_url":"https://api.github.com/users/ericelliott/followers","following_url":"https://api.github.com/users/ericelliott/following{/other_user}","gists_url":"https://api.github.com/users/ericelliott/gists{/gist_id}","starred_url":"https://api.github.com/users/ericelliott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericelliott/subscriptions","organizations_url":"https://api.github.com/users/ericelliott/orgs","repos_url":"https://api.github.com/users/ericelliott/repos","events_url":"https://api.github.com/users/ericelliott/events{/privacy}","received_events_url":"https://api.github.com/users/ericelliott/received_events","type":"User","site_admin":false},"repo":{"id":13372435,"name":"express-error-handler","full_name":"ericelliott/express-error-handler","owner":{"login":"ericelliott","id":364727,"avatar_url":"https://avatars.githubusercontent.com/u/364727?v=3","gravatar_id":"","url":"https://api.github.com/users/ericelliott","html_url":"https://github.com/ericelliott","followers_url":"https://api.github.com/users/ericelliott/followers","following_url":"https://api.github.com/users/ericelliott/following{/other_user}","gists_url":"https://api.github.com/users/ericelliott/gists{/gist_id}","starred_url":"https://api.github.com/users/ericelliott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericelliott/subscriptions","organizations_url":"https://api.github.com/users/ericelliott/orgs","repos_url":"https://api.github.com/users/ericelliott/repos","events_url":"https://api.github.com/users/ericelliott/events{/privacy}","received_events_url":"https://api.github.com/users/ericelliott/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ericelliott/express-error-handler","description":"A graceful error handler for Express and Restify applications.","fork":false,"url":"https://api.github.com/repos/ericelliott/express-error-handler","forks_url":"https://api.github.com/repos/ericelliott/express-error-handler/forks","keys_url":"https://api.github.com/repos/ericelliott/express-error-handler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ericelliott/express-error-handler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ericelliott/express-error-handler/teams","hooks_url":"https://api.github.com/repos/ericelliott/express-error-handler/hooks","issue_events_url":"https://api.github.com/repos/ericelliott/express-error-handler/issues/events{/number}","events_url":"https://api.github.com/repos/ericelliott/express-error-handler/events","assignees_url":"https://api.github.com/repos/ericelliott/express-error-handler/assignees{/user}","branches_url":"https://api.github.com/repos/ericelliott/express-error-handler/branches{/branch}","tags_url":"https://api.github.com/repos/ericelliott/express-error-handler/tags","blobs_url":"https://api.github.com/repos/ericelliott/express-error-handler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ericelliott/express-error-handler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ericelliott/express-error-handler/git/refs{/sha}","trees_url":"https://api.github.com/repos/ericelliott/express-error-handler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ericelliott/express-error-handler/statuses/{sha}","languages_url":"https://api.github.com/repos/ericelliott/express-error-handler/languages","stargazers_url":"https://api.github.com/repos/ericelliott/express-error-handler/stargazers","contributors_url":"https://api.github.com/repos/ericelliott/express-error-handler/contributors","subscribers_url":"https://api.github.com/repos/ericelliott/express-error-handler/subscribers","subscription_url":"https://api.github.com/repos/ericelliott/express-error-handler/subscription","commits_url":"https://api.github.com/repos/ericelliott/express-error-handler/commits{/sha}","git_commits_url":"https://api.github.com/repos/ericelliott/express-error-handler/git/commits{/sha}","comments_url":"https://api.github.com/repos/ericelliott/express-error-handler/comments{/number}","issue_comment_url":"https://api.github.com/repos/ericelliott/express-error-handler/issues/comments/{number}","contents_url":"https://api.github.com/repos/ericelliott/express-error-handler/contents/{+path}","compare_url":"https://api.github.com/repos/ericelliott/express-error-handler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ericelliott/express-error-handler/merges","archive_url":"https://api.github.com/repos/ericelliott/express-error-handler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ericelliott/express-error-handler/downloads","issues_url":"https://api.github.com/repos/ericelliott/express-error-handler/issues{/number}","pulls_url":"https://api.github.com/repos/ericelliott/express-error-handler/pulls{/number}","milestones_url":"https://api.github.com/repos/ericelliott/express-error-handler/milestones{/number}","notifications_url":"https://api.github.com/repos/ericelliott/express-error-handler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ericelliott/express-error-handler/labels{/name}","releases_url":"https://api.github.com/repos/ericelliott/express-error-handler/releases{/id}","created_at":"2013-10-07T00:55:12Z","updated_at":"2015-02-02T07:16:47Z","pushed_at":"2014-12-07T00:32:46Z","git_url":"git://github.com/ericelliott/express-error-handler.git","ssh_url":"git@github.com:ericelliott/express-error-handler.git","clone_url":"https://github.com/ericelliott/express-error-handler.git","svn_url":"https://github.com/ericelliott/express-error-handler","homepage":"","size":326,"stargazers_count":49,"watchers_count":49,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":49,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10"},"html":{"href":"https://github.com/ericelliott/express-error-handler/pull/10"},"issue":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/issues/10"},"comments":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/ericelliott/express-error-handler/statuses/b90babea3ce84c8eb97fd56aa8404b67d62dc208"}}}}