refactor error handling, fixes #3070, #3171

This changes quite a few things on how errors and handled. The purpose is to provide consistency in error handling making it easier to work with returned errors and write test cases. Since error handling logic was added in several different places I thought it would be wise to put it all in one place and make use of existing patterns as much as possible.

The goal is to have the most common errors defined in `errors.js` as instances of `PouchError` and have all error logic pass through `errors.error` (and in some cases `errors.generateErrorFromResponse`. The former creates a new error object depending on the type of error passed (eg. validation error, missing doc error, etc) and the later provides a single place which determines what type of error is being returned from a transaction (depending on the `message` and/or the `status` properties).

As a result #3070 is fixed - the correct document `id`s and `reason` properties are now passed along with each error. #3171 is also fixed - the `message` property of a returned error is always a string and is in most cases the string specified in `errors.js` (where the error type is defined), and `reason` property is always the `reason` property of the error thrown by a transaction (can be of any type).

Another issue resolved (previously unreported) is that since the same error object was reused for each doc error (in bulk doc transactions) this resulted in an error describing just the last document's error. Since now a new error is being created for each document this is no longer an issue.

Another issue resolved (again, unreported) is that in certain cases the error `message` returned was not the correct one describing the error, since the determination of which error to return was done depending on the `name` property (eg. `bad_request`, `missing`) and there are multiple error instances with the same `name` but different `message`.

Going forward, I propose to add another test, `test.errors.js` which will explicitly test the `status`,  `message`, and `reason` properties of returned errors for all transactions. Considering the changes in this PR, this would be fairly trivial - just a lot of copy & pasting.

*Notes*

Some test cases are commented out ( `// todo: does not work in pouchdb-server.`) due to pending PRs:
- https://github.com/pouchdb/express-pouchdb/pull/154
- https://github.com/daleharvey/pouchdb-express-router/pull/4

When/if these are merged those test cases should pass.