# promise/prefer-catch

> Require `catch()` instead of a second argument to `then()`

The second argument of `then(a, b)` only handles a rejection from before the `then()`. If `a` itself throws, `b` isn't called. A `catch()` after the `then()` handles both.

The rule only reports a `then()` call with two arguments when it's a statement by itself. One that's returned, awaited, assigned, or followed by more of the chain isn't reported.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"promise/prefer-catch" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
loadItems().then(render, showError); // an error in render is not handled
```

{/* bad */}
```js
loadItems().then(null, showError);
```

Not reported:

{/* good */}
```js
loadItems().then(render).catch(showError);
loadItems().catch(showError);
```

{/* good */}
```js
function refresh() {
  return loadItems().then(render, showError);
}
```
