apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

Add RequestError typescript definition #248

Closed j3k0 closed 3 years ago

j3k0 commented 3 years ago

Overview

Errors triggered by nano are extended with additional fields, this commits adds the typescript definition for them.

The name "RequestError" was chosen because it seems like it all nano errors are triggered by a request (a 'socket' or a 'couch' error).

I considered "NanoError", but the full type nano.NanoError doesn't sound better than nano.RequestError and no other interface have been prefixed with "Nano".

I've extracted the error fields from nano.js.

Testing recommendations

There's no typescript tests so far, I included this change in my typescript project.

This change can affect users if they uses nano with callbacks incorrectly, their project could fail building.

Errors are simple to fix. For example, on my project there was an instance where I used error.status instead of error.statusCode. Another issue is that I passed a callback that expected Error | undefined for the error field while nano sends Error | null.

Checklist