From bb5a18653075ed57e89ce1965eccd8893d9e6458 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 13 Nov 2012 20:01:18 -0800 Subject: Timeout if exchange can't be fetched --- app.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app.coffee b/app.coffee index 44c95739..715ea64e 100644 --- a/app.coffee +++ b/app.coffee @@ -1,4 +1,3 @@ - express = require('express') http = require('http') path = require('path') @@ -55,6 +54,11 @@ app.get('/:user/transactions', (req, res) -> app.get('/ticker', (req, res) -> + t = setTimeout(-> + res.writeHead(500, {'Content-Type': 'text/plain'}) + res.end() + , 2000) + options = host: 'bitcoincharts.com', path: '/t/depthcalc.json?symbol=' + req.query.symbol + '&type=bid&amount=1000¤cy=true' @@ -62,8 +66,10 @@ app.get('/ticker', (req, res) -> require('http').get(options, (r) -> r.setEncoding('utf-8') r.on('data', (chunk) -> + clearTimeout(t) res.send(chunk) - ) + res.end() + ) ) ) -- cgit v1.2.3