-
-
Save nfroidure/4663804 to your computer and use it in GitHub Desktop.
This file contains 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
// Chainable API for URIBuilder | |
var uri = new URLBuilder(logErrorHandler) | |
.parse('bad_url_format') | |
.addQueryParam('param','value') | |
.setPort('443') | |
.toString(); | |
function logErrorHandler(err, url_object){ | |
if('parse_error'===err.type) | |
console.log(err.message); | |
return url_object; | |
} | |
// XXXXXXXXXXXXXX OR XXXXXXXXXXXXXXX | |
// Chainable API for URIBuilder | |
var uri = new URLBuilder() | |
.parse('bad_url_format') | |
.addQueryParam('param','value') | |
.setPort('443') | |
.toString(); | |
if(uri===null) | |
{ | |
console.log('error') | |
} | |
// Maybe the 2 solutions | |
// Or throw exception if i suppose the parsed string is never a user input ? | |
// Not sure it's good to suppose as well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative:
No real need for EventEmitter (still, better if you have it) you can implement it manually or call it
onError
or whatever.I still prefer exceptions, becasue as soon as input is invalid, the rest of the operations is senseless. Particularly: what will
toString()
return?That's something I don't like in moment.js for example: give invalid (or unsufficient) input and you may have outputs like "NaN/NaN/NaN" I would really have preferred an exception here :s