From 734f58e2c10a66cf32dd17da5ec982e95acb705b Mon Sep 17 00:00:00 2001 From: Michal-Dziedzinski Date: Mon, 22 Jul 2019 09:40:44 +0200 Subject: [PATCH 1/3] Fix mail sending and add error logger --- CHANGELOG.md | 2 ++ core/modules/mailer/store/index.ts | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cf396f14..dfc21cd167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed AMP Product page - @przspa (#3227) - Fixed when store has updated, but plugin didn't called - @serzilo (#3238) - Add ./packages as volume to docker-compose.yml - @cewald (#3251) +- Fixed mail sending and add error logger - @Michal-Dziedzinski ### Changed / Improved @@ -47,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added catching of errors when ES is down - @qiqqq - Added debounce for updating quantity method in the cart - @andrzejewsky (#3191) - New modules API and rewrite - @filrak, @JCown (#3144) + ## [1.10.0-rc.2] - UNRELEASED ### Fixed diff --git a/core/modules/mailer/store/index.ts b/core/modules/mailer/store/index.ts index 4a2162be78..d433430202 100644 --- a/core/modules/mailer/store/index.ts +++ b/core/modules/mailer/store/index.ts @@ -1,3 +1,4 @@ +import { Logger } from '@vue-storefront/core/lib/logger' import MailItem from '../types/MailItem' import { Module } from 'vuex' import config from 'config' @@ -12,11 +13,11 @@ export const mailerStore: Module = { .then(res => res.json()) .then(res => { if (res.code === 200) { - fetch(processURLAddress(config.mailer.endpoint.send()), { + fetch(processURLAddress(config.mailer.endpoint.send), { method: 'POST', mode: 'cors', headers: { - 'Accept': 'application/json', + Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -25,12 +26,18 @@ export const mailerStore: Module = { }) }) .then(res => resolve(res)) - .catch(() => reject()) + .catch(e => { + Logger.error(e, 'mailer')() + return reject() + }) } else { reject() } }) - .catch(() => reject()) + .catch(e => { + Logger.error(e, 'mailer')() + return reject() + }) }) } } From ad0073f5bf3f175b575ff489834eab3a5cdef639 Mon Sep 17 00:00:00 2001 From: Michal-Dziedzinski Date: Tue, 23 Jul 2019 08:32:39 +0200 Subject: [PATCH 2/3] replace promise by async/await --- core/modules/mailer/store/index.ts | 45 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/core/modules/mailer/store/index.ts b/core/modules/mailer/store/index.ts index d433430202..aad78a6073 100644 --- a/core/modules/mailer/store/index.ts +++ b/core/modules/mailer/store/index.ts @@ -7,13 +7,15 @@ import { processURLAddress } from '@vue-storefront/core/helpers' export const mailerStore: Module = { namespaced: true, actions: { - sendEmail (context, letter: MailItem) { - return new Promise((resolve, reject) => { - fetch(processURLAddress(config.mailer.endpoint.token)) - .then(res => res.json()) - .then(res => { - if (res.code === 200) { - fetch(processURLAddress(config.mailer.endpoint.send), { + async sendEmail (context, letter: MailItem) { + try { + const res = await fetch(processURLAddress(config.mailer.endpoint.token)) + const resData = await res.json() + if (resData.code === 200) { + try { + const res = await fetch( + processURLAddress(config.mailer.endpoint.send), + { method: 'POST', mode: 'cors', headers: { @@ -22,23 +24,22 @@ export const mailerStore: Module = { }, body: JSON.stringify({ ...letter, - token: res.result + token: resData.result }) - }) - .then(res => resolve(res)) - .catch(e => { - Logger.error(e, 'mailer')() - return reject() - }) - } else { - reject() - } - }) - .catch(e => { + } + ) + return res + } catch (e) { Logger.error(e, 'mailer')() - return reject() - }) - }) + throw new Error(e) + } + } else { + throw new Error(resData.code) + } + } catch (e) { + Logger.error(e, 'mailer')() + throw new Error(e) + } } } } From b802c4e3a0b020e246d5f5fa99216a17fa2e289f Mon Sep 17 00:00:00 2001 From: Patryk Tomczyk <13100280+patzick@users.noreply.github.com> Date: Tue, 23 Jul 2019 09:51:23 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75049278fa..22793558cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed when store has updated, but plugin didn't called - @serzilo (#3238) - Fixed first call of prepareStoreView when SSR - @resubaka (#3244) - Add ./packages as volume to docker-compose.yml - @cewald (#3251) -- Fixed mail sending and add error logger - @Michal-Dziedzinski +- Fixed mail sending and add error logger - @Michal-Dziedzinski (#3265) ### Changed / Improved