You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,14 +103,21 @@ The following plugin options allow you to customize the default behavior of `hap
103
103
-**showErrors**: `(boolean)`, default: `false` — by default, the plugin is disabled and keeps hapi's default error handling behavior
104
104
-**template**: `(string)`, no default — provide the template name that you want to render with `h.view(template, errorData)`
105
105
-**toTerminal**: `(boolean)`, default: `true` — print pretty errors to the terminal as well (enabled by default)
106
+
-**links**: `(array)`, defaults to Google and Stack Overflow icons that are linked with the error message as the search term (enabled by default). Pass an empty array `[]` to disable the default links
* hapi’s request and error objects don’t match the
19
+
* expected structure in Youch. We need to adjust
20
+
* properties to display them correctly.
21
+
*/
20
22
request.url=request.path
21
-
22
-
// assign httpVersion -> same as with request.url
23
23
request.httpVersion=request.raw.req.httpVersion
24
-
25
-
// let Youch show the error’s status code
26
24
error.status=error.output.statusCode
27
25
28
-
// pretty error printing on terminal or web view
29
-
returnnewYouch(error,request)
26
+
try{
27
+
constyouch=newYouch(error,request)
28
+
29
+
links.forEach(link=>youch.addLink(link))
30
+
31
+
returnyouch
32
+
}catch(error){
33
+
console.error(error)
34
+
throwerror
35
+
}
30
36
}
31
37
32
38
/**
@@ -55,6 +61,44 @@ function matches (str, regex) {
55
61
returnstr&&str.match(regex)
56
62
}
57
63
64
+
/**
65
+
* Returns a link to Google that includes
66
+
* the error message as the search
67
+
* term. The link is an SVG icon.
68
+
*
69
+
* @param {Object} error
70
+
*
71
+
* @returns {String}
72
+
*/
73
+
functiongoogleIcon(error){
74
+
return`<a rel="noopener noreferrer" target="_blank" href="https://google.com/search?q=${encodeURIComponent(error.message)}" title="Search Google for "${error.message}"">
75
+
<!-- Google icon by Picons.me, found at https://www.iconfinder.com/Picons -->
0 commit comments