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
Merged

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

merged 8 commits into from
Sep 26, 2019

Conversation

gibkigonzo
Copy link
Collaborator

Related issues

closes #3621

Short description and why it's useful

with this change silentMode will be checked on the same level as task.silent

Which environment this relates to

Check your case. In case of any doubts please read about Release Cycle

  • Test version (https://test.storefrontcloud.io) - this is a new feature or improvement for Vue Storefront. I've created branch from develop branch and want to merge it back to develop
  • RC version (https://next.storefrontcloud.io) - this is a stabilisation fix for Release Candidate of Vue Storefront. I've created branch from release branch and want to merge it back to release
  • Stable version (https://demo.storefrontcloud.io) - this is an important fix for current stable version. I've created branch from hotfix or master branch and want to merge it back to hotfix

Upgrade Notes and Changelog

  • No upgrade steps required (100% backward compatibility and no breaking changes)
  • I've updated the Changelog on how to port existing VS sites with this new feature

IMPORTANT NOTICE - Remember to update CHANGELOG.md with description of your change

Contribution and currently important rules acceptance

const message = typeof jsonResponse.result === 'string' ? jsonResponse.result : typeof jsonResponse.result.result === 'string' ? jsonResponse.result.result : jsonResponse.result.message

const errorMessage = isObject(jsonResponse.result) ? (jsonResponse.result.result || jsonResponse.result.message) : jsonResponse.result
const errorCode = isObject(jsonResponse.result) ? jsonResponse.result.code : jsonResponse.code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not to sure about this jsonRespone.code but let me analyse that 😄

@andrzejewsky
Copy link
Contributor

andrzejewsky commented Sep 26, 2019

try with this:

        const hasError = (jsonResponse) => {
          if (typeof jsonResponse.result === 'string') {
            return true
          }

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

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

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

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

          jsonResponse.result.message
        }

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

and put these function on the top of the file, now these conditions will be more readable, feel free to improve that, and please test if it works as previously. Would be nice to move this to the helpers and write some unit test

tkostuch added 2 commits September 26, 2019 14:53
…com:gibkigonzo/vue-storefront into bugfix/check-silentMode-same-as-task-silent
@gibkigonzo
Copy link
Collaborator Author

@andrzejewsky thanks, I've applied your suggestions :)

@rain2o
Copy link
Contributor

rain2o commented Sep 26, 2019

Thanks for the fast reaction everyone! I like the cleanup of the code you did while fixing this. Looks good!

@andrzejewsky andrzejewsky merged commit fd23a49 into vuestorefront:develop Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants