Misc Webhooks Fixes (#12038)

* fix(webhooks): don t parse response as json

* upgrade got to version 10

* remove old header

* fix tests

* fix email auth

* add migration

* update email error

* split migration in two
This commit is contained in:
Matteo Pagliazzi
2020-04-02 21:48:47 +02:00
committed by GitHub
parent e92ff9737a
commit 28bc843779
9 changed files with 326 additions and 87 deletions
+4 -4
View File
@@ -133,9 +133,9 @@ export async function sendTxn (mailingInfoArray, emailType, variables, personalV
return got.post(`${EMAIL_SERVER.url}/job`, {
retry: 5, // retry the http request to the email server 5 times
timeout: 60000, // wait up to 60s before timing out
auth: `${EMAIL_SERVER.auth.user}:${EMAIL_SERVER.auth.password}`,
json: true,
body: {
username: EMAIL_SERVER.auth.user,
password: EMAIL_SERVER.auth.password,
json: {
type: 'email',
data: {
emailType,
@@ -149,7 +149,7 @@ export async function sendTxn (mailingInfoArray, emailType, variables, personalV
backoff: { delay: 10 * 60 * 1000, type: 'fixed' },
},
},
}).catch(err => logger.error(err));
}).json().catch(err => logger.error(err, 'Error while sending an email.'));
}
return null;
+2 -2
View File
@@ -13,10 +13,10 @@ function sendWebhook (webhook, body, user) {
const { url, lastFailureAt } = webhook;
got.post(url, {
body,
json: true,
json: body,
timeout: 30000, // wait up to 30s before timing out
retry: 3, // retry the request up to 3 times
// Not calling .json() to parse the response because we simply ignore it
}).catch(webhookErr => {
// Log the error
logger.error(webhookErr, 'Error while sending a webhook request.');
+2
View File
@@ -58,6 +58,8 @@ export const schema = new Schema({
required: true,
validate: [v => validator.isURL(v, {
require_tld: !!IS_PRODUCTION, // eslint-disable-line camelcase
require_protocol: true, // TODO migrate existing ones
protocols: ['http', 'https'],
}), shared.i18n.t('invalidUrl')],
},
enabled: { $type: Boolean, required: true, default: true },