2

How can I force a 504 error in Chrome?

We have a node app that we occasionally get a 504 error from and I wanted do some error handling for 504 errors.

Tom11
  • 2,419
  • 8
  • 30
  • 56
christoffee
  • 633
  • 1
  • 6
  • 15
  • http://stackoverflow.com/questions/6214902/how-to-set-a-timeout-on-a-http-request-in-node maybe this could help – Telmo Ivo Feb 05 '16 at 12:03

1 Answers1

3

Copy this into a file called server.js then run node server.js. If you visit http://localhost:8080 you will be thrown a 504 error.

var http = require('http');
var fs = require('fs');

http.createServer(function (req, res) {
  console.log("Sending 504 error to client");
  res.writeHead(504, {'Content-Type': 'text/plain'});
  res.end();
}).listen(8080);
console.log("Server started on port 8080");
Simon McClive
  • 2,516
  • 3
  • 17
  • 13
  • 1
    Since I posted this I thought about building a web service to do this for any http status code. It turns out someone has already built it. http://httpbin.org It supports lots of different things but the status API does what you want. http://httpbin.org/status/504 – Simon McClive Feb 16 '16 at 11:47