---
name: "onError"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.10.0" }
title: "ty.onError - Listen for miniapp error events such as script errors or API call errors, triggered at the same time and with the same parameters as App.onError"
---

## onError

> [VERSION] Base Library >= 2.10.0

### Description

Listen for Mini Program error events, such as script errors or API call failures. This event has the same callback timing and parameters as App.onError.

### Parameters

`(callback: Function)`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `callback` | `(error: string) => void` | Yes | Mini Program error event callback |

### Return Value

None


### Examples

#### Listen for mini program error events

```js
// app.js
App({
  onLaunch() {
    ty.onError((error) => {
      console.log('An error occurred in the Mini Program', error);
    });
  },
});
```
