Ignore:
Timestamp:
03/10/14 11:50:04 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Schema patterns should be anchored.
  • App returns validation result on error.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/app.js

    r497 r499  
    225225    function putDocument(id,rev,type,doc) {
    226226        var priv = stripAndReturnPrivates(doc);
    227         if ( doc.type === type && validator(doc, schema).valid ) {
     227        var valid;
     228        if ( doc.type === type && (valid = validator(doc, schema)).valid ) {
    228229            var opts = rev ? {headers:{'If-Match':'"'+rev+'"'}} : {};
    229230            return HTTPResult.fromResponsePromise(couch.put(id,doc,opts).response,
     
    241242            });
    242243        } else {
    243             return new HTTPResult(400,{error: "Document failed schema verification."});
     244            return new HTTPResult(400,{error: "Document failed schema verification.", valid: valid});
    244245        }
    245246    }
     
    262263    function postDocument(type,doc) {
    263264        var priv = stripAndReturnPrivates(doc);
    264         if ( doc.type === type && validator(doc, schema).valid ) {
     265        var valid;
     266        if ( doc.type === type && (valid = validator(doc, schema)).valid ) {
    265267            return HTTPResult.fromResponsePromise(couch.post(doc).response,
    266268                                                  handleUnknownError)
     
    274276            });
    275277        } else {
    276             return new HTTPResult(400,{error: "Document failed schema verification."});
     278            return new HTTPResult(400,{error: "Document failed schema verification.", valid: valid});
    277279        }
    278280    }
Note: See TracChangeset for help on using the changeset viewer.