Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mail sending and add error logger #3265

Merged
merged 5 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +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 (#3265)

### Changed / Improved

Expand Down
44 changes: 26 additions & 18 deletions core/modules/mailer/store/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -6,32 +7,39 @@ import { processURLAddress } from '@vue-storefront/core/helpers'
export const mailerStore: Module<any, any> = {
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: {
'Accept': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
...letter,
token: res.result
token: resData.result
})
})
.then(res => resolve(res))
.catch(() => reject())
Michal-Dziedzinski marked this conversation as resolved.
Show resolved Hide resolved
} else {
reject()
}
})
.catch(() => reject())
})
}
)
return res
} catch (e) {
Logger.error(e, 'mailer')()
throw new Error(e)
}
} else {
throw new Error(resData.code)
}
} catch (e) {
Logger.error(e, 'mailer')()
throw new Error(e)
}
}
}
}