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

Access from plugin context clientside #42

Closed
ThomasKientz opened this issue Nov 15, 2018 · 9 comments
Closed

Access from plugin context clientside #42

ThomasKientz opened this issue Nov 15, 2018 · 9 comments
Labels

Comments

@ThomasKientz
Copy link

ThomasKientz commented Nov 15, 2018

I am trying to automatically track network errors.

export default function({ $axios, store, error, $raven }) {
  $axios.onError(e => {
    if (process.client) {
      $raven.captureException(e.response.data);
    }
    return Promise.reject(e);
  });
}

But $raven is undefined.

Any ideas ? I have read #19 but I don't find the solution.

Thanks

This question is available on Nuxt community (#c34)
@ghost ghost closed this as completed Nov 15, 2018
@ghost ghost added the cmty:question label Nov 15, 2018
@ghost
Copy link

ghost commented Nov 15, 2018

This issue as been imported as question since it does not respect sentry-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/sentry-module/issues/c34.

@aldarund
Copy link
Member

  1. there no $raven in latest version of nuxt sentry, its $sentry
  2. export default function({ $axios, store, error, {app: { $sentry } }) {

@ThomasKientz
Copy link
Author

ThomasKientz commented Nov 15, 2018

@aldarund Thanks !

I was using v1 of sentry module using $raven.

So I have updated module to v2.

Some details

I don't know why, It doesn't work with destructured assignement :

export default function({ $axios, store, error, app: { $sentry } }) {

=> $sentry is still undefined.

It works though with :

export default function({ $axios, store, error, app }) {

and then accessing $sentry : app.$sentry

@DiederikvandenB
Copy link
Collaborator

Could you maybe share some more code? In which file are you calling this code, what are you importing, etc.

@ThomasKientz
Copy link
Author

@DiederikvandenB It's a simple nuxt plugin :

// plugins/axios.js
export default function({ $axios, store, error, app }) {
  $axios.onError(e => {
    if (process.client) {
      app.$sentry.configureScope(scope => {
        scope.setExtra("request", e);
        app.$sentry && app.$sentry.captureException(e.response.data);
      });
    }
    return Promise.reject(e);
  });
}
// nuxt.config.js
module.exports = {
  modules: [
    "@nuxtjs/axios",
  ],
  plugins: [
    "@/plugins/axios",
  ],
}

@seandelaney
Copy link

What was the solution?

I have a similar issue where $sentry is undefined within my plugin: https://cmty.app/nuxt/sentry-module/issues/c36

@ThomasKientz
Copy link
Author

ThomasKientz commented Nov 26, 2018

@seandelaney solution for me was (as you can see in the thread)

using

app.$sentry

with module updated to v2.

@ThomasKientz
Copy link
Author

Ok I think I finally get it ! My guess :

Sentry is working in client side only, but the plugin is not registered for client side only cause I need it to be initiated in server side (as I need for axios)

But I am calling $sentry only in $axios.onError(e => { ... app.$sentry }) through app and its working cause by the time $sentry had time to be injected !

@DiederikvandenB
Copy link
Collaborator

Sorry for not responding! Completely forgot. Very glad you were able to resolve it yourself.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants