Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-dev-errors

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-dev-errors - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

5

CHANGELOG.md
# Changelog
## Version 2.1.0 (2018-02-12)
- `add` status code to Youch error and show it in the view
- `update` example code in readme to async/await
- `update` examples to fully async/await code
## Version 2.0.1 (2017-11-06)

@@ -4,0 +9,0 @@ - `update` dependencies to latest stable releases

43

examples/default.js

@@ -6,2 +6,3 @@ 'use strict'

// create new server instance
// add server’s connection information
const server = new Hapi.Server({

@@ -12,24 +13,26 @@ host: 'localhost',

// register plugins to server instance
server
.register([
{
plugin: require('../'),
options: {
showErrors: process.env.NODE_ENV !== 'production'
}
async function launchIt () {
await server.register({
plugin: require('../'),
options: {
showErrors: process.env.NODE_ENV !== 'production'
}
])
.then(() => {
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
h.notAvailable()
}
})
})
// start your server
server.start()
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
h.notAvailable()
}
})
try {
await server.start()
console.log('Server running at: ' + server.info.uri)
})
} catch (err) {
throw err
}
}
launchIt()

@@ -13,5 +13,4 @@ 'use strict'

// register plugins to server instance
server
.register([
async function launchIt () {
await server.register([
{

@@ -29,27 +28,28 @@ plugin: require('vision')

])
.then(() => {
server.views({
engines: {
html: require('handlebars')
},
path: Path.resolve(__dirname, 'views'),
layout: 'layout',
isCached: process.env.NODE_ENV !== 'production'
})
server.route({
method: 'GET',
path: '/',
handler: (request, reply) => {
reply.notAvailable()
}
})
server.views({
engines: {
html: require('handlebars')
},
path: Path.resolve(__dirname, 'views'),
layout: 'layout',
isCached: process.env.NODE_ENV !== 'production'
})
// start your server
server.start().then(() => {
console.log('Server running at: ' + server.info.uri)
})
server.route({
method: 'GET',
path: '/',
handler: (request, reply) => {
reply.notAvailable()
}
})
.catch(err => {
try {
await server.start()
console.log('Server running at: ' + server.info.uri)
} catch (err) {
throw err
})
}
}
launchIt()

@@ -12,29 +12,27 @@ 'use strict'

// register plugins to server instance
server
.register([
{
plugin: require('../'),
options: {
showErrors: process.env.NODE_ENV !== 'production',
useYouch: true
}
async function youchIt () {
await server.register({
plugin: require('../'),
options: {
showErrors: process.env.NODE_ENV !== 'production',
useYouch: true
}
])
.then(() => {
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
h.notAvailable()
}
})
})
// start your server
server.start().then(() => {
console.log('Server running at: ' + server.info.uri)
})
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
h.notAvailable()
}
})
.catch(err => {
try {
await server.start()
console.log('Server running at: ' + server.info.uri)
} catch (err) {
throw err
})
}
}
youchIt()

@@ -15,3 +15,3 @@ 'use strict'

*/
const register = function register (server, options) {
function register (server, options) {
// default option values

@@ -42,15 +42,15 @@ const defaults = {

// to change the default error handling behavior (if enabled)
server.ext('onPreResponse', (request, h) => {
// response shortcut
const response = request.response
server.ext('onPreResponse', async (request, h) => {
// error response shortcut
const error = request.response
// only show `bad implementation` developer errors (status code 500)
if (response.isBoom && response.output.statusCode === 500) {
if (error.isBoom && error.output.statusCode === 500) {
const accept = request.raw.req.headers.accept
const statusCode = response.output.statusCode
const statusCode = error.output.statusCode
const errorResponse = {
title: response.output.payload.error,
title: error.output.payload.error,
statusCode,
message: response.message,
message: error.message,
method: request.raw.req.method,

@@ -60,3 +60,3 @@ url: request.url.path,

payload: request.raw.req.method !== 'GET' ? request.payload : '',
stacktrace: response.stack.replace(/[a-z_-\d]+.js:\d+:\d+/gi, '<mark>$&</mark>')
stacktrace: error.stack.replace(/[a-z_-\d]+.js:\d+:\d+/gi, '<mark>$&</mark>')
}

@@ -86,15 +86,19 @@

// let Youch show the error’s status code
error.status = statusCode
// create new Youch instance and reply rendered HTML
const youch = new Youch(response, req)
const youch = new Youch(error, req)
return youch.toHTML().then(html => {
return h
.response(html)
.type('text/html')
.code(statusCode)
})
// render response HTML template
const html = await youch.toHTML()
return h
.response(html)
.type('text/html')
.code(statusCode)
}
// prepare the error template and replace `%placeholder%` with error specific details
const responseHtml = errorTemplate.replace(/%(\w+)%/g, (full, token) => {
const html = errorTemplate.replace(/%(\w+)%/g, (full, token) => {
return errorResponse[token] || ''

@@ -105,3 +109,3 @@ })

return h
.response(responseHtml)
.response(html)
.type('text/html')

@@ -108,0 +112,0 @@ .code(statusCode)

{
"name": "hapi-dev-errors",
"description": "Return better error details and skip the look at command line to catch the issue.",
"version": "2.0.1",
"version": "2.1.0",
"author": "Future Studio <info@futurestud.io>",

@@ -10,8 +10,8 @@ "bugs": {

"dependencies": {
"hoek": "~5.0.2",
"youch": "~2.0.5"
"hoek": "~5.0.3",
"youch": "~2.0.7"
},
"devDependencies": {
"boom": "~7.1.1",
"code": "~5.1.2",
"code": "~5.2.0",
"eslint-config-standard": "~10.2.1",

@@ -22,6 +22,6 @@ "eslint-plugin-import": "~2.8.0",

"eslint-plugin-standard": "~3.0.1",
"hapi": "~17.0.1",
"hapi": "~17.2.0",
"husky": "~0.14.3",
"lab": "~15.1.2",
"vision": "~5.1.0"
"lab": "~15.2.2",
"vision": "~5.3.1"
},

@@ -28,0 +28,0 @@ "engines": {

@@ -11,2 +11,12 @@ <p align="center">

------
<p align="center"><sup>Development of this hapi plugin is supported by <a href="https://futurestud.io">Future Studio University 🚀</a></sup>
<br><b>
Join the <a href="https://futurestud.io/university">Future Studio University and Skyrocket in Node.js</a></b>
</p>
------
## Introduction

@@ -66,3 +76,3 @@ A hapi plugin to return an error view for web requests, providing more details of the issue. Also, provides the

```js
server.register({
await server.register({
plugin: require('hapi-dev-errors'),

@@ -72,7 +82,5 @@ options: {

}
}).then(() => {
// went smooth like chocolate :)
}).catch(err => {
// handle plugin registration error
})
// went smooth like chocolate :)
```

@@ -89,3 +97,3 @@

```js
server.register({
await server.register({
plugin: require('hapi-dev-errors'),

@@ -96,7 +104,5 @@ options: {

}
}).then(() => {
// went smooth like chocolate :)
}).catch(err => {
// handle plugin registration error
})
// went smooth like chocolate :)
```

@@ -129,3 +135,3 @@

- [hapi tutorial series](https://futurestud.io/tutorials/hapi-get-your-server-up-and-running) with 70+ tutorials
- [hapi tutorial series](https://futurestud.io/tutorials/hapi-get-your-server-up-and-running) with 80+ tutorials
- [Youch](https://github.com/poppinss/youch) - Pretty error reporting for Node.js

@@ -132,0 +138,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc