Changeset 527 for Dev/trunk/src/server/util/couch.js
- Timestamp:
- 03/23/14 17:26:12 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/server/util/couch.js
r525 r527 1 1 var request = require('./request') 2 2 , _ = require('underscore') 3 , HTTPResult = require('./http-result') 3 4 ; 4 5 … … 42 43 } 43 44 44 function couchRequest (method, url, body, opts) { 45 function couchRequest (method, url, body, opts, retries) { 46 body = body || {}; 47 retries = _.isNumber(retries) ? retries : 3; 45 48 var options = { 46 49 method: method, 47 headers: { 48 'Content-Type': 'application/json; charset=utf-8', 49 'Accept': 'application/json' 50 }, 51 body: JSON.stringify(stringifyFunctions(body || {})) 50 headers: {}, 51 body: stringifyFunctions(body), 52 json: true, 53 timeout: 5000 52 54 }; 53 55 if (opts) { … … 56 58 } 57 59 return request(url, options) 58 .handle({ 59 '-1': _.identity, 60 default: function(status,result) { return JSON.parse(result); } 61 }); 60 .handle(function(status,body){ 61 if ( _.isUndefined(body) ) { 62 if ( retries > 0) { 63 return couchRequest(method,url,body,opts,retries-1); 64 } else { 65 return new HTTPResult(-1,new Error("No response after several retries.")); 66 } 67 } else { 68 return body; 69 } 70 }); 62 71 } 63 72
Note: See TracChangeset
for help on using the changeset viewer.