Skip to content

Commit

Permalink
Merge pull request #3265 from Michal-Dziedzinski/bugfix/feedbackMail
Browse files Browse the repository at this point in the history
Fix mail sending and add error logger
  • Loading branch information
patzick committed Jul 23, 2019
2 parents 53d79f7 + b802c4e commit 8b828e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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())
} 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)
}
}
}
}

0 comments on commit 8b828e0

Please sign in to comment.