Skip to content
Permalink
Browse files

fixup panics and properly redirect to slack server (#141)

* fixup panics and properly redirect to slack server
  • Loading branch information
adamdecaf authored and emedvedev committed Jan 10, 2020
1 parent e5e51df commit c5d494b1a1d1b30ed2edbd2f3f2a1903245cfa74
Showing with 22 additions and 7 deletions.
  1. +6 −3 assets/client.js
  2. +8 −2 lib/index.js
  3. +8 −2 test/index.js
@@ -52,15 +52,18 @@ function invite(chan, coc, email, gcaptcha_response_value, fn) {
email: email
})
.end(function (res) {
if (res.body.redirectUrl) {
if (res && res.response) {
res = res.response
}
if (res && res.body && res.body.redirectUrl) {
window.setTimeout(function () {
topLevelRedirect(res.body.redirectUrl)
}, 1500)
}
if (res.error) {
if (res && res.error) {
return fn(new Error(res.body.msg || 'Server error'))
}
fn(null, res.body.msg)
fn(null, 'Invite sent')
})
}

@@ -240,9 +240,15 @@ function slackin({
redirectUrl: `https://${org}.slack.com/`,
});
}
return res.status(400).json({ msg: inviteErr.message });
return res.status(400).json({
msg: inviteErr.message,
redirectUrl: `https://${org}.slack.com/`,
});
}
return res.status(200).json({ msg: 'WOOT. Check your email!' });
return res.status(200).json({
msg: 'WOOT. Check your email!',
redirectUrl: `https://${org}.slack.com/`,
});
});
};

@@ -57,7 +57,10 @@ describe('slackin', () => {
.post('/invite')
.send({ email: 'foo@example.com' })
.expect('Content-Type', /json/)
.expect(200, { msg: 'WOOT. Check your email!' })
.expect(200, {
msg: 'WOOT. Check your email!',
redirectUrl: 'https://myorg.slack.com/',
})
.end(done);
});

@@ -81,7 +84,10 @@ describe('slackin', () => {
.post('/invite')
.send({ email: 'foo@example.com' })
.expect('Content-Type', /json/)
.expect(400, { msg: 'other error' })
.expect(400, {
msg: 'other error',
redirectUrl: 'https://myorg.slack.com/',
})
.end(done);
});
});

0 comments on commit c5d494b

Please sign in to comment.
You can’t perform that action at this time.