Slide 1

Slide 1 text

ERROR HANDLING MADE EASY JS VERSION

Slide 2

Slide 2 text

Stratos Pavlakis Lead Engineer @Workable @th3hunt

Slide 3

Slide 3 text

Error Handling

Slide 4

Slide 4 text

Why bother?

Slide 5

Slide 5 text

Why bother? Cause good error handling builds TRUST 
 between our users and our product

Slide 6

Slide 6 text

Why bother? Cause good error handling builds TRUST 
 between our users and our product It IS part of the UX

Slide 7

Slide 7 text

Why bother? Cause good error handling builds TRUST 
 between our users and our product It IS part of the UX

Slide 8

Slide 8 text

errors for developers

Slide 9

Slide 9 text

NullPointerException Java

Slide 10

Slide 10 text

RxCocoa.RxCocoaURLError Swift

Slide 11

Slide 11 text

e Javascript

Slide 12

Slide 12 text

err Javascript

Slide 13

Slide 13 text

InvalidLoginError Problem Domain

Slide 14

Slide 14 text

errors for users?

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

WHAT’S WRONG WITH THAT?

Slide 17

Slide 17 text

– Younger self “Fix the copy and you’re set”

Slide 18

Slide 18 text

Is that the case?

Slide 19

Slide 19 text

Is that the case? Why do we keep getting this kind of 
 cryptic messages and bad UX? I asked at some point…

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

WE DON’T DESIGN FOR ERROR

Slide 22

Slide 22 text

Designing for errors

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

DESIGNING FOR ERRORS what does that mean? Take #1

Slide 26

Slide 26 text

DESIGNING FOR ERRORS MEANS… to anticipate errors!

Slide 27

Slide 27 text

DESIGNING FOR ERRORS MEANS… ▸ List and identify them during design meetings to anticipate errors!

Slide 28

Slide 28 text

DESIGNING FOR ERRORS MEANS… ▸ List and identify them during design meetings ▸ Getting the product team involved to anticipate errors!

Slide 29

Slide 29 text

– Younger self “I got a solid theory… Let’s do this!”

Slide 30

Slide 30 text

“In theory there is no difference between theory and practice…

Slide 31

Slide 31 text

– Jan L. A. van de Snepscheut “In theory there is no difference between theory and practice… In practice there is.”

Slide 32

Slide 32 text

A story of errors

Slide 33

Slide 33 text

A story of errors inspired from true events

Slide 34

Slide 34 text

A STORY OF ERRORS WALTER

Slide 35

Slide 35 text

A STORY OF ERRORS WALTER ▸ Senior Engineer

Slide 36

Slide 36 text

A STORY OF ERRORS WALTER ▸ Senior Engineer ▸ Anticipates all errors.

Slide 37

Slide 37 text

A STORY OF ERRORS INSTANT BUY

Slide 38

Slide 38 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application.

Slide 39

Slide 39 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application. • Unauthenticated

Slide 40

Slide 40 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application. • Unauthenticated • Out of stock

Slide 41

Slide 41 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application. • Unauthenticated • Out of stock • CSRF

Slide 42

Slide 42 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application. • Unauthenticated • Out of stock • CSRF • Offline

Slide 43

Slide 43 text

A STORY OF ERRORS INSTANT BUY Walter adds error handling an early feature of the web application. • Unauthenticated • Out of stock • CSRF • Offline • Unknown

Slide 44

Slide 44 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { });

Slide 45

Slide 45 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { });

Slide 46

Slide 46 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break;

Slide 47

Slide 47 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break;

Slide 48

Slide 48 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: alert(`You seem to be offline. No worries…’); break;

Slide 49

Slide 49 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: alert(`You seem to be offline. No worries…’); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; }

Slide 50

Slide 50 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: alert(`You seem to be offline. No worries…’); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); }

Slide 51

Slide 51 text

A STORY OF ERRORS INSTANT BUY instantBuy(item) .then(() => thanksForBuying(item)) .catch(error => { }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: alert(`You seem to be offline. No worries…’); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); } logError(error);

Slide 52

Slide 52 text

A STORY OF ERRORS JESSE

Slide 53

Slide 53 text

A STORY OF ERRORS JESSE ▸ Junior Engineer

Slide 54

Slide 54 text

A STORY OF ERRORS JESSE ▸ Junior Engineer ▸ Hired 2 weeks ago

Slide 55

Slide 55 text

A STORY OF ERRORS JESSE ▸ Junior Engineer ▸ Hired 2 weeks ago ▸ Anticipates no errors. At all!

Slide 56

Slide 56 text

A STORY OF ERRORS SAVE FOR LATER

Slide 57

Slide 57 text

A STORY OF ERRORS SAVE FOR LATER Jesse adds no error handling to the Nth feature of the web application… still 1st one for him.

Slide 58

Slide 58 text

A STORY OF ERRORS SAVE FOR LATER

Slide 59

Slide 59 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi

Slide 60

Slide 60 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated

Slide 61

Slide 61 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated • Out of stock

Slide 62

Slide 62 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated • Out of stock • CSRF

Slide 63

Slide 63 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated • Out of stock • CSRF • Offline

Slide 64

Slide 64 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated • Out of stock • CSRF • Offline • Unknown

Slide 65

Slide 65 text

A STORY OF ERRORS SAVE FOR LATER After a couple of code reviews, QA testing and a demo with bad WiFi • Unauthenticated • Out of stock • CSRF • Offline • Unknown with a twist - silently sync when online

Slide 66

Slide 66 text

saveForLater(item) .catch(error => { A STORY OF ERRORS SAVE FOR LATER });

Slide 67

Slide 67 text

saveForLater(item) .catch(error => { A STORY OF ERRORS });

Slide 68

Slide 68 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break;

Slide 69

Slide 69 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break;

Slide 70

Slide 70 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break;

Slide 71

Slide 71 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; }

Slide 72

Slide 72 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); }

Slide 73

Slide 73 text

saveForLater(item) .catch(error => { A STORY OF ERRORS }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); } logError(error);

Slide 74

Slide 74 text

saveForLater(item) .catch(error => { A STORY OF ERRORS copy-paste has a twist - swallow & send when online }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); } logError(error);

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

We end up with..

Slide 81

Slide 81 text

We end up with.. Boilerplate, Repetition

Slide 82

Slide 82 text

We end up with.. Boilerplate, Repetition No standard way of handling errors

Slide 83

Slide 83 text

We end up with.. Boilerplate, Repetition No standard way of handling errors Cognitive overhead

Slide 84

Slide 84 text

We end up with.. Boilerplate, Repetition No standard way of handling errors Cognitive overhead Inefficient error reporting

Slide 85

Slide 85 text

We end up with.. Boilerplate, Repetition No standard way of handling errors Cognitive overhead Inefficient error reporting Friction in development cycles

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

DESIGNING FOR ERRORS what does that mean? Take #2

Slide 89

Slide 89 text

DESIGNING FOR ERRORS MEANS… (REVISED)

Slide 90

Slide 90 text

DESIGNING FOR ERRORS MEANS… (REVISED) ▸ Anticipating errors

Slide 91

Slide 91 text

DESIGNING FOR ERRORS MEANS… (REVISED) ▸ Anticipating errors ▸ Getting the product team involved

Slide 92

Slide 92 text

DESIGNING FOR ERRORS MEANS… (REVISED) ▸ Anticipating errors ▸ Getting the product team involved ▸ Making error handling easy by engineering it

Slide 93

Slide 93 text

DESIGNING FOR ERRORS checkpoint

Slide 94

Slide 94 text

DESIGNING FOR ERRORS checkpoint what should guide our solution?

Slide 95

Slide 95 text

DESIGNING FOR ERRORS KINDS OF ERRORS

Slide 96

Slide 96 text

DESIGNING FOR ERRORS KINDS OF ERRORS - Business ‣ authentication ‣ validation ‣ stale data

Slide 97

Slide 97 text

DESIGNING FOR ERRORS KINDS OF ERRORS - Business ‣ authentication ‣ validation ‣ stale data - Non business ‣ network ‣ storage ‣ device i/o (camera/mic/speakers/GPS) ‣ bugs

Slide 98

Slide 98 text

DESIGNING FOR ERRORS KINDS OF ERRORS - Business ‣ authentication ‣ validation ‣ stale data - Non business ‣ network ‣ storage ‣ device i/o (camera/mic/speakers/GPS) ‣ bugs

Slide 99

Slide 99 text

DESIGNING FOR ERRORS KINDS OF ERRORS - Business ‣ authentication ‣ validation ‣ stale data - Non business ‣ network ‣ storage ‣ device i/o (camera/mic/speakers/GPS) ‣ bugs cross-cut, common errors

Slide 100

Slide 100 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Present ▸ Shy ▸ Comprehensible ▸ Actionable ▸ Targeted ▸ Reportable

Slide 101

Slide 101 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Shy ▸ Comprehensible ▸ Actionable ▸ Targeted ▸ Reportable ▸ Is in place, timely and consistent

Slide 102

Slide 102 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Comprehensible ▸ Actionable ▸ Targeted ▸ Reportable ▸ Is in place, timely and consistent ▸ Communicates errors only if necessary

Slide 103

Slide 103 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Actionable ▸ Targeted ▸ Reportable ▸ Is in place, timely and consistent ▸ Communicates errors only if necessary ▸ Communicates errors in a comprehensible way

Slide 104

Slide 104 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Targeted ▸ Reportable ▸ Is in place, timely and consistent ▸ Communicates errors only if necessary ▸ Communicates errors in a comprehensible way ▸ Suggests how to resolve if possible

Slide 105

Slide 105 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Reportable ▸ Is in place, timely and consistent ▸ Communicates errors only if necessary ▸ Communicates errors in a comprehensible way ▸ Suggests how to resolve if possible ▸ Makes errors have the smallest area of effect

Slide 106

Slide 106 text

DESIGNING FOR ERRORS WE NEED ERROR HANDLING THAT IS… ▸ Is in place, timely and consistent ▸ Communicates errors only if necessary ▸ Communicates errors in a comprehensible way ▸ Suggests how to resolve if possible ▸ Makes errors have the smallest area of effect ▸ Lets the product owners & engineers know

Slide 107

Slide 107 text

and we need it to be easy

Slide 108

Slide 108 text

and we need it to be easy easy as in …

Slide 109

Slide 109 text

Error handling as easy as ordering a burger

Slide 110

Slide 110 text

lettuce bun tomato bacon cheddar onion patty

Slide 111

Slide 111 text

“Can I have a burger with baked flour, salted cured pork, relatively hard off-white natural cheese, tomato fruit and minced beef meat please?” - noone ever

Slide 112

Slide 112 text

Instead we say… “The usual…” or “Cowboy burger with extra bacon without the onions”

Slide 113

Slide 113 text

What we actually want

Slide 114

Slide 114 text

✓ Natural language What we actually want

Slide 115

Slide 115 text

✓ “offline” instead of “err.status === 0 || err.msg…” What we actually want

Slide 116

Slide 116 text

✓ “offline” instead of “err.status === 0 || err.msg…” ✓ Presets of default actions for common errors What we actually want

Slide 117

Slide 117 text

✓ “offline” vs “err.status === 0 || err.msg…” ✓ Presets of default actions for common errors ✓ Customise presets in a dynamic way ➡ Add actions ➡ Override actions ➡ Skip actions ➡ Log or… not What we actually want

Slide 118

Slide 118 text

ErrorHandler A library that provides a declarative fluent API for flexible error handling

Slide 119

Slide 119 text

ERROR HANDLER LET’S TAKE A LOOK ErrorHandler .build() .when(‘out-of-stock’, notifyOutOfStock) .when(‘unauthenticated’, promptForSignIn) .when(‘offline’, promptToRetry) .when(422, {type: ‘stale-pay-info’}, getPaymentInfo) .when(430, refreshCSRFToken) .when(err => err instanceof KaboomError, onKaboom) .whenNot('offline', sendToAnalytics) .always(enableSubmit) .logWith(new SentryLogger()) .handle(err);

Slide 120

Slide 120 text

ERROR HANDLER BASIC API when(matcher, action) alias(name, matcher) when(alias, action) when(alias, options, action) whenNot(matcher, action) otherwise(action) always(action) logWith(logger)

Slide 121

Slide 121 text

ERROR HANDLER BASIC API handle(err, options) run(function) retry()

Slide 122

Slide 122 text

ERROR HANDLER BASIC API - ALIAS ErrorHandler .alias('offline', err => err.status === 0) ErrorHandler .alias( (tag) => typeof tag === 'number', (tag, err) => err.status === tag ) ErrorHandler .default() .when('offline', waitToGetOnline) .when(401, requestSignIn) .when(CustomError, onCustomError) .handle(err)

Slide 123

Slide 123 text

ERROR HANDLER MOAAR API ErrorHandler .default() .when(‘foo', (err, handler) => { handleFoo(); handler.skipFollowing(); }) .when(err => err.match(/fo/), foHappened) .when('bar', (err, handler) => { handleBar(); handler.skipDefaults(); }) .when('validation', ‘max-length-exceeded‘, handleMaxLen) .when('validation', ‘profanity‘, handleProfanity) .when(KaboomError, kaboomHappened) .always(() => enableSubmitButton()) .logWith(new SentryLogger()) .run(submitLoginForm);

Slide 124

Slide 124 text

Our strategy

Slide 125

Slide 125 text

Our strategy Setup a default ErrorHandler once

Slide 126

Slide 126 text

Our strategy Setup a default ErrorHandler once Customise the default ErrorHandler when needed based on the context

Slide 127

Slide 127 text

Most of the time all we will need is… } catch (err) { } ErrorHandler.default().handle(err);

Slide 128

Slide 128 text

and sometimes we need… } catch (err) { } ErrorHandler .default() .when(‘foo', onFoo) .when('bar', onBar) .handle(err);

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

GANDALF APPROVES

Slide 131

Slide 131 text

Back to our story

Slide 132

Slide 132 text

saveForLater(item) .catch(error => { A STORY OF ERRORS copy-paste / default throughout the app has a twist }); switch (error.status) { case 401: requestSignIn(); break; case 430: // CSRF promptToRefreshSession(); break; case 0: onlineTasks.push(() => saveForLater(item)); break; case 422: if (error.response === 'out of stock') { this.showOutOfStockDialog(); break; } default: alert('The operation is unavailable'); } logError(error);

Slide 133

Slide 133 text

turns to

Slide 134

Slide 134 text

A STORY OF ERRORS ErrorHandler .default() .when('offline', () => { onlineTasks.push(() => saveForLater(item)); }) .handle(err); saveForLater(item) .catch(error => { });

Slide 135

Slide 135 text

We get to.. Boilerplate, Repetition No standard way of handling Cognitive overhead Inefficient error reporting Friction in development cycles

Slide 136

Slide 136 text

We get to.. No standard way of handling Cognitive overhead Inefficient error reporting Zero boilerplate, minimum repetition Friction in development cycles

Slide 137

Slide 137 text

We get to.. Cognitive overhead Inefficient error reporting Zero boilerplate, minimum repetition Very standard way of handling errors Friction in development cycles

Slide 138

Slide 138 text

We get to.. Inefficient error reporting Zero boilerplate, minimum repetition Very standard way of handling errors Readable domain related code Friction in development cycles

Slide 139

Slide 139 text

We get to.. Zero boilerplate, minimum repetition Very standard way of handling errors Readable domain related code Efficient error tracking Friction in development cycles

Slide 140

Slide 140 text

We get to.. Zero boilerplate, minimum repetition Very standard way of handling errors Readable domain related code Efficient error tracking One less problem to deal with

Slide 141

Slide 141 text

– Swift Apprentice, Chapter 22 (Error Handling) “Error handling is the art of failing gracefully”

Slide 142

Slide 142 text

Any Questions? No error you can’t .handle() Swift - https://github.com/Workable/swift-error-handler.git Java - https://github.com/Workable/java-error-handler.git Javascript - coming soon