Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge a752f0b into ac9d968
Browse files Browse the repository at this point in the history
  • Loading branch information
kinson committed Jun 8, 2018
2 parents ac9d968 + a752f0b commit 8ef4fe1
Show file tree
Hide file tree
Showing 7 changed files with 2,559 additions and 577 deletions.
15 changes: 9 additions & 6 deletions example/route.js
Expand Up @@ -4,8 +4,8 @@ const Hapi = require('hapi')
const Joi = require('joi')
const Relish = require('../')()

const server = new Hapi.Server()
server.connection({
const server = new Hapi.Server({
host: '0.0.0.0',
port: 3000
})

Expand Down Expand Up @@ -38,9 +38,12 @@ server.route({
}
}
},
handler: (request, reply) => reply()
handler: (request, h) => h.response()
})

server.start(() => {
console.log('Server running at:', server.info.uri)
})
const init = async () => {
await server.start()
console.log(`Server is running at ${server.info.uri}`)
}

init()
15 changes: 9 additions & 6 deletions example/server.js
Expand Up @@ -12,8 +12,8 @@ const Relish = require('../')({
}
})

const server = new Hapi.Server()
server.connection({
const server = Hapi.Server({
host: '0.0.0.0',
port: 3000,
routes: {
validate: {
Expand Down Expand Up @@ -42,9 +42,12 @@ server.route({
}
}
},
handler: (request, reply) => reply()
handler: (request, h) => h.response()
})

server.start(() => {
console.log('Server running at:', server.info.uri)
})
const init = async () => {
await server.start()
console.log(`Server is running at ${server.info.uri}`)
}

init()
13 changes: 8 additions & 5 deletions index.js
Expand Up @@ -14,7 +14,7 @@ const Relish = function Relish (opts) {
this._opts = opts ? Hoek.applyToDefaults(internals.defaults, opts) : internals.defaults

this.parseError = (error) => {
return error.data.details.map((i) => {
return error.details.map((i) => {
let err = {
key: i.context.key,
path: i.path.join('.'),
Expand Down Expand Up @@ -56,17 +56,20 @@ const Relish = function Relish (opts) {
return this.exports
}

this.exports.failAction = (request, reply, source, error) => {
this.exports.failAction = (request, h, err) => {
// parse error object
const errors = this.parseError(error)
const errors = this.parseError(err)

// build main error message
const errorMessage = errors.map((e) => e.message).join(', ')

// retrieve validation failure source
const source = err.output.payload.validation.source

// format error response
error = this.formatResponse(error, source, errorMessage, errors)
err = this.formatResponse(err, source, errorMessage, errors)

return reply(error)
return err
}

return this.exports
Expand Down

0 comments on commit 8ef4fe1

Please sign in to comment.