0.1.3 • Published 4 years ago
entix v0.1.3
entix
Getting Started: index.js
global['entix'] = require('entixio')()
const bodyparser = require('koa-body') // middleware
entix.use(bodyparser())
// load more global middleware here ...
entix.startServer()
Adding ErrorHandlers: index.js
global['entix'] = require('entixio')()
const { ValidationError } = require('entixio').joi
const { UniqueViolationError } = require('entixio').objection
const { JsonWebTokenError } = require('jsonwebtoken')
const bodyparser = require('koa-body')
const validationErrorHandler = async ({ctx, error}) => {
if(error instanceof ValidationError){
console.log('jackopt')
ctx.status = 422
const { details, _original } = error
error = { original: _original, details: {}}
details.map(d => error.details[d.context.key] = d.message)
return error
}
}
const databaseErrorHandler = async ({ctx, error}) => {
if(error instanceof UniqueViolationError){
ctx.status = 422
const key = error.columns.pop()
error = { original: ctx.request.body, details: {}}
error.details[key] = `this ${key} is already taken`
return error
}
}
const jwtErrorHandler = async ({ctx, error}) => {
if(error instanceof JsonWebTokenError){
const managed = ['invalid signature', 'jwt expired', 'jwt malformed', 'jwt must be provided', 'jwt token']
if(managed.includes(error.message)){
ctx.status = 401
error = { message: error.message }
return error
}
}
}
entix.use(bodyparser())
entix.loadErrorHandler(validationErrorHandler)
entix.loadErrorHandler(databaseErrorHandler)
entix.loadErrorHandler(jwtErrorHandler)
entix.startServer()
0.1.2
4 years ago
0.1.1
4 years ago
0.1.3
4 years ago
0.1.0
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.1
4 years ago
0.0.0
4 years ago
0.6.5
5 years ago
0.6.2
5 years ago
0.6.4
5 years ago
0.6.1
5 years ago
0.6.0
5 years ago
0.5.10
5 years ago
0.5.9
5 years ago