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

check silentMode in errors on the same level as task.silent #3626

Merged
merged 8 commits into from
Sep 26, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix login errors with mailchimp - @gibkigonzo (#3612)
- Hydration error on homepage - @patzick (#3609)
- Fix adding products with custom options - @andrzejewsky (#3597)
- check silentMode in errors on the same level as task.silent - @gibkigonzo (#3621)
- Add missing parameters (`size`,`start`) to `quickSearchByQuery()` in `attribute/list` action - @cewald (#3627)

### Changed / Improved
Expand Down
21 changes: 21 additions & 0 deletions core/lib/sync/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const hasResponseError = (jsonResponse): boolean => {
if (typeof jsonResponse.result === 'string') {
return true
}

const hasMessage = jsonResponse.result.result || jsonResponse.result.message

return Boolean(hasMessage) && jsonResponse.result.code !== 'ENOTFOUND'
}

export const getResponseMessage = (jsonResponse): string => {
if (typeof jsonResponse.result === 'string') {
return jsonResponse.result
}

if (typeof jsonResponse.result.result === 'string') {
return jsonResponse.result.result
}

return jsonResponse.result.message
}
11 changes: 3 additions & 8 deletions core/lib/sync/task.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import Vue from 'vue'
import i18n from '@vue-storefront/i18n'
import isNaN from 'lodash-es/isNaN'
import isUndefined from 'lodash-es/isUndefined'
import toString from 'lodash-es/toString'
import fetch from 'isomorphic-fetch'
import * as localForage from 'localforage'
import rootStore from '@vue-storefront/core/store'
import { adjustMultistoreApiUrl, currentStoreView } from '@vue-storefront/core/lib/multistore'
import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus'
import Task from '@vue-storefront/core/lib/sync/types/Task'
import { Logger } from '@vue-storefront/core/lib/logger'
import { TaskQueue } from '@vue-storefront/core/lib/sync'
import * as entities from '@vue-storefront/core/lib/store/entities'
import UniversalStorage from '@vue-storefront/core/lib/store/storage'
import { StorageManager } from '@vue-storefront/core/lib/storage-manager'
import { processURLAddress } from '@vue-storefront/core/helpers'
import { serial } from '@vue-storefront/core/helpers'
import config from 'config'
import { onlineHelper } from '@vue-storefront/core/helpers'
import { hasResponseError, getResponseMessage } from '@vue-storefront/core/lib/sync/helpers'

export function _prepareTask (task) {
const taskId = entities.uniqueEntityId(task) // timestamp as a order id is not the best we can do but it's enough
Expand Down Expand Up @@ -128,12 +125,10 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
}
}

if (!task.silent && jsonResponse.result && (typeof jsonResponse.result === 'string' || (((jsonResponse.result.result || jsonResponse.result.message) && jsonResponse.result.code !== 'ENOTFOUND') && !silentMode))) {
const message = typeof jsonResponse.result === 'string' ? jsonResponse.result : typeof jsonResponse.result.result === 'string' ? jsonResponse.result.result : jsonResponse.result.message

if (!task.silent && jsonResponse.result && hasResponseError(jsonResponse) && !silentMode) {
rootStore.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t(message),
message: i18n.t(getResponseMessage(jsonResponse)),
action1: { label: i18n.t('OK') }
})
}
Expand Down