title: How to avoid Hapi.js sending 400 error when Validating Request with Joi
body: <p>Hapi.js Validation with Joi + <code>failAction</code> question.</p>
  
  <h2>Situation</h2>
  
  <p>We want to build a "<em>traditional</em>" <strong>server-side</strong>-<strong><em>only</em></strong>
  rendered application using <strong>Hapi</strong>.</p>
  
  <p>I'm trying to <em>understand</em> how to avoid returning a "<em>raw</em>" <code>400</code>
  error to the client when <code>Joi</code> validation <em>fails</em>:</p>
  
  <p><img src="https://cloud.githubusercontent.com/assets/194400/10234331/a863744a-688b-11e5-9eb8-5e41d0f570e2.png" alt="register-iphone4s-sim"></p>
  
  <p>We want to intercept this "<em>email not allowed to be empty</em>" <strong>validation error</strong> and display it in the html template back to the client,
  instead of simply returning the <code>400</code> error.</p>
  
  <p><a href="https://github.com/hapijs/joi/issues/725#issuecomment-144482794" rel="noreferrer">@AdriVanHoudt</a> advised that we should:</p>
  
  <blockquote>
    <p>"Look at failAction under <a href="http://hapijs.com/api#route-options" rel="noreferrer">http://hapijs.com/api#route-options</a> "</p>
  </blockquote>
  
  <p>So we added <code>failAction: 'log'</code> to the <code>/register</code> route handler:</p>
  
  <pre><code>{
    method: '*',
    path: '/register',
    config: {
      validate: {
        payload : register_fields,
        failAction: 'log'
      }
    },
    handler: register_handler
  }
  </code></pre>
  
  <p>See code in:
  <a href="https://github.com/nelsonic/hapi-validation-question/blob/master/server.js" rel="noreferrer"><strong>server.js</strong></a></p>
  
  <p>the <code>register_handler</code> is:</p>
  
  <pre><code>function register_handler(request, reply, source, error) {
    console.log(request.payload);
    console.log(' - - - - - - - - - - - - - - - - - - - - -');
    console.log(source)
    console.log(' - - - - - - - - - - - - - - - - - - - - -');
    console.log(error)
    return reply('welcome!');
  }
  </code></pre>
  
  <p>I am expecting to see an error in the terminal/console
  but when I try to <code>console.log</code> the <code>handler</code> :</p>
  
  <pre><code>- - - - - - - - - - - - - - - - - - - - -
  undefined
  - - - - - - - - - - - - - - - - - - - - -
  undefined
  </code></pre>
  
  <p>I asked the question on GitHub: <a href="https://github.com/hapijs/joi/issues/725" rel="noreferrer">https://github.com/hapijs/joi/issues/725</a>
  but have not yet got an answer with a <em>good</em> <strong><em>example</em></strong>.
  Full code if you have time to help: <a href="https://github.com/nelsonic/hapi-validation-question" rel="noreferrer">https://github.com/nelsonic/hapi-validation-question</a></p>