'use strict';

exports.ValidationError = class extends Error {
  constructor(errors) {

    super(errors.name)
    this.name = 'IllegalAccessError'
    this.message = 'Validation error';
    this.errors = errors;
    this.status = '400';
    this.statusText = 'Internal Server Error';
  }
}

@@ -8,16 +8,46 @@
 rict';%0A%0A
+const _ = require('lodash');%0A%0A
 exports.
@@ -105,17 +105,16 @@
 or(error
-s
 ) %7B%0A%0A   
@@ -129,116 +129,318 @@
 rror
-s.name
 )%0A
+%0A
     
-this.name = 'IllegalAccessError'%0A    this.message = 'Validation error';%0A    this.errors = errors
+// flat all errors for hapi like validation error response%0A    const flat = error.details.map(details =%3E %7B%0A      return %7B%0A        key: _.map(details.context),%0A        source: details.path.split('.')%5B0%5D%0A      %7D%0A    %7D)%0A%0A    error.name = '';%0A    this.name = error.toString();%0A    this.error = 'Bad Request'
 ;%0A  
@@ -452,16 +452,20 @@
 s.status
+Code
  = '400'
@@ -479,44 +479,128 @@
 his.
-statusText = 'Internal Server Error'
+validation = %7B%0A      key: _.flatten(_.map(flat, 'key')),%0A      source: _.uniq(_.flatten(_.map(flat, 'source')))%5B0%5D%0A    %7D
 ;%0A  

add error transformer for hapi like validation response error