Last active
August 29, 2015 13:56
-
-
Save paulvstheworld/9105613 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // example of response with errors | |
| var respObjWithErrors = { | |
| errors: [{ | |
| key: 'could.not.insert', | |
| msg: "couldn't insert new usr into db" | |
| }], | |
| data: { /* some data goes here */} | |
| }; | |
| var respObj = { errors:[], data:{/* some data goes here */} } | |
| someAlreadyDefinedCallback(respObj); | |
| /* some controller function that gets passed as | |
| a callback to a database query function */ | |
| var someControllerFunction = function(respObj) { | |
| var errorMessagesArr = []; | |
| if (respObj.errors.length > 0){ | |
| for(var i=0; i<respObj.errors.length; i++) { | |
| errorMessagesArr.push(respObj.errors[i].msg); | |
| } | |
| resp.send(errorMessagesArr.join("\n")); | |
| } | |
| else { | |
| resp.send(respObj.data); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment