Changeset 527 for Dev/trunk/src/server/api/util.js
- Timestamp:
- 03/23/14 17:26:12 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/server/api/util.js
r525 r527 34 34 }; 35 35 36 var handleException = exports.handleException = function(error) { 37 return new HTTPResult(500,{ 38 reason: error.message, 39 filename: error.filename, 40 lineNumber: error.lineNumber 41 }); 42 }; 36 43 var handleUnknownResponse = exports.handleUnknownResponse = function(status,error) { 37 44 return new HTTPResult(500,{error: error.reason}); … … 77 84 return couch.get(url) 78 85 .handle({ 86 '-1': _.identity, 79 87 200: handleRowValues, 80 88 404: function() { return {error: "Cannot find collection of type "+type}; }, … … 89 97 return couch.get(id,opts) 90 98 .handle({ 99 '-1': _.identity, 91 100 200: function(doc){ 92 101 if ( doc.type !== type ) { … … 114 123 return couch.put(id,doc,opts) 115 124 .handle({ 125 '-1': _.identity, 116 126 201: function(res){ 117 127 doc._id = res.id; … … 133 143 return couch.delete(id,opts) 134 144 .handle({ 145 '-1': _.identity, 135 146 200: identity, 136 147 409: function(error) { … … 149 160 return couch.post(doc) 150 161 .handle({ 162 '-1': _.identity, 151 163 201: function(response) { 152 164 doc._id = response.id; … … 164 176 return function(req,res) { 165 177 getDocumentsOfType(type) 178 .handle({'-1': handleException}) 166 179 .handle(res.send.bind(res)); 167 180 }; … … 173 186 getDocument(id,rev,type) 174 187 .handle({ 188 '-1': function(result) { 189 handleException(result) 190 .handle(res.send.bind(res)); 191 }, 175 192 200: function(doc){ 176 193 res.set({ … … 189 206 putDocument(id,rev,type,doc) 190 207 .handle({ 208 '-1': function(result) { 209 handleException(result) 210 .handle(res.send.bind(res)); 211 }, 191 212 201: function(doc) { 192 213 res.set({ … … 204 225 var rev = etags.parse(req.header('If-Match'))[0] || (doc && doc._rev); 205 226 deleteDocument(id,rev) 227 .handle({'-1': handleException}) 206 228 .handle(res.send.bind(res)); 207 229 }; … … 212 234 postDocument(type,doc) 213 235 .handle({ 236 '-1': function(result) { 237 handleException(result) 238 .handle(res.send.bind(res)); 239 }, 214 240 201: function(doc) { 215 241 res.set({
Note: See TracChangeset
for help on using the changeset viewer.