Skip to content

Instantly share code, notes, and snippets.

@craigbeck
Created June 4, 2015 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigbeck/b4af45937fe73e01b83c to your computer and use it in GitHub Desktop.
Save craigbeck/b4af45937fe73e01b83c to your computer and use it in GitHub Desktop.
Fix hapi.js issue with BadRequest when parsing invalid cookie value

Problem

  • multple apps sharing the same cookie domain
  • one app (express.js) is using a secure cookie express:sess and express:sess.sig
  • the hapi.js app tries to parse these cookies and fails returning 400 BadRequest error to client

I don't want hapi to return an error response to the client just because it gets a cookie it cant parse and doesn't care about. I tried setting

server.config({
  state: {
    cookie: {
       failaction: "log"
    }
  }
  // other config omitted
});

but cookie or { state: { failAction: ... }} was not allowed and prevented the server from starting.

Solution

 server.connection({
  host: "0.0.0.0",
  port: 8081,
  routes: {
    cors: true
  },
  state: {
    ignoreErrors: true //  <== this works
  }
});

It's not entirely clear form the docs what to do but peeking at the source for statehood shows it is expecting an object that has property ignoreErrors -- nthing at all like what the hapi docs say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment