Ignore:
Timestamp:
03/23/14 17:26:12 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Dropped request module for a simple one we wrote ourselves using the native Node modules. Hopefully this one will not suffer from the problem that sometimes empty bodies are returned even when the statuscode and content-length of the request are ok & present.
  • Handle exceptions better in HTTPResult chain, they were hoisted in unknown responses before. Should we not include them in default processing, because they are special?
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/api/util.js

    r525 r527  
    3434    };
    3535
     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    };
    3643    var handleUnknownResponse = exports.handleUnknownResponse = function(status,error) {
    3744        return new HTTPResult(500,{error: error.reason});
     
    7784        return couch.get(url)
    7885        .handle({
     86            '-1': _.identity,
    7987            200: handleRowValues,
    8088            404: function() { return {error: "Cannot find collection of type "+type}; },
     
    8997        return couch.get(id,opts)
    9098        .handle({
     99            '-1': _.identity,
    91100            200: function(doc){
    92101                if ( doc.type !== type ) {
     
    114123            return couch.put(id,doc,opts)
    115124            .handle({
     125                '-1': _.identity,
    116126                201: function(res){
    117127                    doc._id = res.id;
     
    133143            return couch.delete(id,opts)
    134144            .handle({
     145                '-1': _.identity,
    135146                200: identity,
    136147                409: function(error) {
     
    149160            return couch.post(doc)
    150161            .handle({
     162                '-1': _.identity,
    151163                201: function(response) {
    152164                    doc._id = response.id;
     
    164176        return function(req,res) {
    165177            getDocumentsOfType(type)
     178            .handle({'-1': handleException})
    166179            .handle(res.send.bind(res));
    167180        };
     
    173186            getDocument(id,rev,type)
    174187            .handle({
     188                '-1': function(result) {
     189                    handleException(result)
     190                    .handle(res.send.bind(res));
     191                },
    175192                200: function(doc){
    176193                    res.set({
     
    189206            putDocument(id,rev,type,doc)
    190207            .handle({
     208                '-1': function(result) {
     209                    handleException(result)
     210                    .handle(res.send.bind(res));
     211                },
    191212                201: function(doc) {
    192213                    res.set({
     
    204225            var rev = etags.parse(req.header('If-Match'))[0] || (doc && doc._rev);
    205226            deleteDocument(id,rev)
     227            .handle({'-1': handleException})
    206228            .handle(res.send.bind(res));
    207229        };
     
    212234            postDocument(type,doc)
    213235            .handle({
     236                '-1': function(result) {
     237                    handleException(result)
     238                    .handle(res.send.bind(res));
     239                },
    214240                201: function(doc) {
    215241                    res.set({
Note: See TracChangeset for help on using the changeset viewer.