Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Add custom error when in maintenance mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Sep 19, 2017
1 parent d237ded commit add9155
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ function json (opts) {
}

// Create an HTTP response error.
function error (status, message) {
function error (response, status, message) {
let e = new Error(`${status}: ${message}`)
e.response = response
e.status = status
return e
}
Expand Down Expand Up @@ -84,9 +85,10 @@ function doLogin (opts, csrf, email, password) {
function getAuthToken (opts) {
opts = normalizeOptions(opts)

return got(`${opts.host}/_/auth/token`, json(opts)).then(({ body }) => {
return got(`${opts.host}/_/auth/token`, json(opts)).then((response) => {
const { body } = response
if (body.status !== 'ok') {
throw error(body.status, body.data[0])
throw error(response, body.status, body.data[0])
}
return body.data[0]
})
Expand All @@ -107,6 +109,9 @@ function guest (opts) {
opts = normalizeOptions(opts)

return got(`${opts.host}/plug-socket-test`, opts).then((res) => {
if (/<title>maintenance mode/.test(res.body)) {
throw error(res, 'maintenanceMode', 'The site is in maintenance mode')
}
const session = getSessionCookie(res.headers['set-cookie'])
opts = addCookieToHeaders(opts, session)
return props({
Expand Down

0 comments on commit add9155

Please sign in to comment.