Skip to content

Commit

Permalink
chore(docs): refactor modules, add info on validation, errors [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Feb 12, 2021
1 parent 7458ece commit 854f55e
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
## Table of Contents

1. [Common Options](#common-options)

1. Modules
1. [autoc](./modules/autoc.md)
1. [historical](./modules/historical.md)
1. [quote](./modules/quote.md)
1. [quoteSummary](./modules/quoteSummary.md)
1. [search](./modules/search.md)
1. [recommendationsBySymbol](./modules/recommendationsBySymbol.md)

1. [Errors Handling](#error-handling)

1. [Modules](#modules)
1. [Error Handling](#error-handling)
1. [Validation](./validation.md)

<a name="common-options"></a>
Expand All @@ -33,15 +24,60 @@ const moduleOpts = {
const result = await yahooFinance.module(query, queryOpts, moduleOpts);
```

<a name="modules"></a>
## Modules

1. [autoc](./modules/autoc.md) - autocomplete, great for symbol lookup.
1. [historical](./modules/historical.md) - historical market prices.
1. [quote](./modules/quote.md) - essential symbol info.
1. [quoteSummary](./modules/quoteSummary.md) - comprehensive symbol info.
1. [search](./modules/search.md) - symbol lookup, news and articles.
1. [recommendationsBySymbol](./modules/recommendationsBySymbol.md) - similar symbols.

<a name="error-handling"></name>
## Error Handling and Validation.
<a name="error-handling"></a>
## Error Handling

Coming soon.
The modules rely on external services and *things can go wrong*. Therefore,
it's important to wrap your use of this library in try..catch statements,
e.g.:

```js
let result;
try {
result = await yahooFinance.quote(symbol);
} catch (error) {
// Inspect error and decide what to do; often, you may want to just abort:
return;
}

doSomethingWith(result); // safe to use in the way you expect
```

So what can go wrong?

* Network errors: request timeouts, no response, etc.
* HTTP errors: internal errors, etc.
* Missing resources, e.g. asking for fund data for a stock.
* Validation errors.

The library goes to great lengths to ensure that if there are no errors,
the result you receive will be in an expected format and structure, that
is safe to use, put in your database, perform calculations with, etc
(but please do let us know if you come across any edge cases).

There is a list of specific errors at [lib/errors.ts](../src/lib/errors.ts)
but generally we'll prevent you from making bad requests with invalid option,
etc.

See also: [Validation](./validation.md)

## Validation

See the [Validation docs](./validation.md).
As per the previous section, if you do receive a result (i.e. if no error is
thrown), it should reliably be in the format you expect. As such, every
received result is validated against the schema we've developed for each
module.

See the [Validation docs](./validation.md) for more info, including how to
continue past validation errors or skip validation entirely, as long as you
understand the risks.

0 comments on commit 854f55e

Please sign in to comment.