fogine / couchbase-odm

CouchbaseODM is a promise-based Node.js ODM for Couchbase
https://fogine.github.io/couchbase-odm
MIT License
12 stars 3 forks source link

not possible to distinguish between not found and wrong name error #8

Closed jurajsimbs closed 8 years ago

jurajsimbs commented 8 years ago

in modelManager.js:

    if (type == 'string') {
        if (!this.models.hasOwnProperty(name)) {
            throw new Error("Model `" + name + "` not found.");
        }
        return this.models[name];
    } else {
        throw new Error("Expected string name of the Model");
    }

for example I'd like catch notFound error and in that case load model from somewhere. Wrong name can stay general Error and I'd pass that to main loop

what do you think?

fogine commented 8 years ago

I agree, the method should definitely throw specific error objects.

Thank you for the suggestion.

fogine commented 8 years ago

Is available on both the develop and v1.0 branches.

if model is not found, it throws CouchbaseODM.errors.ModelNotFoundError for any other error it throws CouchbaseODM.errors.ModelManagerError.