there is inside of the api many times the same-ish code :
let data = this.someCall()
if(data.status){
// work
} else {
// return the error
}
or
if(this.connectLevel >n){
//work
}else {
// return generic error
}
those kind of code are everywhere sometimes in both the api and the application using the api thus finding a way to avoid this duplicated code will improve code clarity as well as quality
proposals :
- the return object could be enhanced with generic methods like
then and else to setup handlers this might have some side effect as sometimes the existence of a then method is used to know if the object can used like a promise
- a method factory can be used to wrap methods and handle basic tests like the connect level although this will probably be complicated hard to maintain and be a bug factory instead of a method factory. This way may also cause trouble for documentation and completion helper inside some IDEs.
there is inside of the api many times the same-ish code :
or
those kind of code are everywhere sometimes in both the api and the application using the api thus finding a way to avoid this duplicated code will improve code clarity as well as quality
proposals :
thenandelseto setup handlers this might have some side effect as sometimes the existence of athenmethod is used to know if the object can used like a promise