SlideShare a Scribd company logo
1 of 14
Download to read offline
Mikhail Kuznetcov
Handling errors in Vue
applications
Vue Global Meetup
04/2020
{ }
About me
Mikhail Kuznetcov
Chapter lead @ ING Amsterdam
Twitter & Github
@shershen08
● Using Vue since 2017
● Teaching Vue since 2019
Question
What tool do you use to log errors in PROD
in your JS/Vue apps?
Handling errors in Vue applications | @shershen08
󾠮 Custom solution
󾠯 Service like Sentry.io / Rollbar / Bugsnag / catchjs
󾠰 We don’t have errors to handle ...
Plain JavaScript exception handling
try {
throw 'myException';
} catch (err) {
// statements to handle any exceptions
} finally {
// cleanup
}
Handling errors in Vue applications | @shershen08
Common types of errors
● Syntax errors
● Runtime errors
● Logical errors
● API errors
Handling errors in Vue applications | @shershen08
Vue API for
handing errors
Layers to capture errors
Handling errors in Vue applications | @shershen08
window
Vue instance
Component
Component level: errorCaptured
export default {
name: 'ErrorBoundary',
errorCaptured(err, vm, info) {
console.log(`Error happened: ${err.toString()}
Additional info : ${info}`);
// important toggle
return false;
}
}
Handling errors in Vue applications | @shershen08
errorCaptured boundary component
import { ErrorBoundary } from "vue-error-boundary";
<ErrorBoundary :fall-back="fallBackHandler">
<ThirdPartyComponent :config="config"/>
</ErrorBoundary>
Handling errors in Vue applications | @shershen08
● vue-error-boundary module
<ErrorBoundary>
<div class="container">
<router-view></router-view>
</div>
</ErrorBoundary>
Component level: renderError
export default {
name: 'ThirdPartyCmpWpapper',
// props,
// methods,
renderError (h, err) {
return h('pre', {
style: { color: 'red' }
}, err.stack)
}
}
Handling errors in Vue applications | @shershen08
● Only works in DEV mode
Global Vue errorHandler
Vue.config.errorHandler = function (err, vm, info) {
// handle error
// `info` is a Vue-specific error info
}
// also Vue.config.warnHandler available for Vue-specific warnings
Handling errors in Vue applications | @shershen08
Also in async mode
export default {
name: 'SomeComponent',
mounted() {
return new Promise((_, reject) => {
setTimeout(() => {
reject('Error happened here');
}, 2000);
});
}
};
Handling errors in Vue applications | @shershen08
window.onerror
window.onerror = function(message, source, line, column, error) {
// do your thing
}
● Need to have Vue.config.errorHandler defined for this to work
Handling errors in Vue applications | @shershen08
Thanks
Please ask your questions in chat:
bit.ly/WorldVueChat
Handling errors in Vue applications | @shershen08
Links:
● Vue Docs vuejs.org/v2/api/#errorHandler
● Global ErrorsService medium.com/js-dojo/vue-js-global-errors-handling-c58aac8aaf0f
● Detailed overview raymondcamden.com/2019/05/01/handling-errors-in-vuejs

More Related Content

Similar to Handling errors in vuejs applications

Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 

Similar to Handling errors in vuejs applications (20)

Lightning Talk: JavaScript Error Handling
Lightning Talk: JavaScript Error HandlingLightning Talk: JavaScript Error Handling
Lightning Talk: JavaScript Error Handling
 
Vuejs
VuejsVuejs
Vuejs
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Php exceptions
Php exceptionsPhp exceptions
Php exceptions
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapy
 
Exception handling
Exception handlingException handling
Exception handling
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
 
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Developing Android Apps
Developing Android AppsDeveloping Android Apps
Developing Android Apps
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Some ways to DRY in Rails
Some ways to DRY in Rails Some ways to DRY in Rails
Some ways to DRY in Rails
 
Error boundaries
Error boundariesError boundaries
Error boundaries
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 

Recently uploaded

TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 

Recently uploaded (20)

Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 

Handling errors in vuejs applications

  • 1. Mikhail Kuznetcov Handling errors in Vue applications Vue Global Meetup 04/2020 { }
  • 2. About me Mikhail Kuznetcov Chapter lead @ ING Amsterdam Twitter & Github @shershen08 ● Using Vue since 2017 ● Teaching Vue since 2019
  • 3. Question What tool do you use to log errors in PROD in your JS/Vue apps? Handling errors in Vue applications | @shershen08 󾠮 Custom solution 󾠯 Service like Sentry.io / Rollbar / Bugsnag / catchjs 󾠰 We don’t have errors to handle ...
  • 4. Plain JavaScript exception handling try { throw 'myException'; } catch (err) { // statements to handle any exceptions } finally { // cleanup } Handling errors in Vue applications | @shershen08
  • 5. Common types of errors ● Syntax errors ● Runtime errors ● Logical errors ● API errors Handling errors in Vue applications | @shershen08
  • 7. Layers to capture errors Handling errors in Vue applications | @shershen08 window Vue instance Component
  • 8. Component level: errorCaptured export default { name: 'ErrorBoundary', errorCaptured(err, vm, info) { console.log(`Error happened: ${err.toString()} Additional info : ${info}`); // important toggle return false; } } Handling errors in Vue applications | @shershen08
  • 9. errorCaptured boundary component import { ErrorBoundary } from "vue-error-boundary"; <ErrorBoundary :fall-back="fallBackHandler"> <ThirdPartyComponent :config="config"/> </ErrorBoundary> Handling errors in Vue applications | @shershen08 ● vue-error-boundary module <ErrorBoundary> <div class="container"> <router-view></router-view> </div> </ErrorBoundary>
  • 10. Component level: renderError export default { name: 'ThirdPartyCmpWpapper', // props, // methods, renderError (h, err) { return h('pre', { style: { color: 'red' } }, err.stack) } } Handling errors in Vue applications | @shershen08 ● Only works in DEV mode
  • 11. Global Vue errorHandler Vue.config.errorHandler = function (err, vm, info) { // handle error // `info` is a Vue-specific error info } // also Vue.config.warnHandler available for Vue-specific warnings Handling errors in Vue applications | @shershen08
  • 12. Also in async mode export default { name: 'SomeComponent', mounted() { return new Promise((_, reject) => { setTimeout(() => { reject('Error happened here'); }, 2000); }); } }; Handling errors in Vue applications | @shershen08
  • 13. window.onerror window.onerror = function(message, source, line, column, error) { // do your thing } ● Need to have Vue.config.errorHandler defined for this to work Handling errors in Vue applications | @shershen08
  • 14. Thanks Please ask your questions in chat: bit.ly/WorldVueChat Handling errors in Vue applications | @shershen08 Links: ● Vue Docs vuejs.org/v2/api/#errorHandler ● Global ErrorsService medium.com/js-dojo/vue-js-global-errors-handling-c58aac8aaf0f ● Detailed overview raymondcamden.com/2019/05/01/handling-errors-in-vuejs