# There are some error coming from third party

**URL:** <https://discuss.elastic.co/t/there-are-some-error-coming-from-third-party/358095>\
**Category:** Elastic Observability\
**Tags:** elastic-stack-monitoring\
**Created:** [April 24, 2024, 7:14am UTC](https://discuss.elastic.co/t/there-are-some-error-coming-from-third-party/358095 "2024-04-24T07:14:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maheta\_Hemendra\_Bhav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maheta_hemendra_bhav/32/123992_2.png) [@Maheta\_Hemendra\_Bhav](https://discuss.elastic.co/u/Maheta_Hemendra_Bhav)\
**Post date:** [April 24, 2024, 7:14am UTC](https://discuss.elastic.co/t/there-are-some-error-coming-from-third-party/358095/1 "2024-04-24T07:14:03Z")

</div>

There are some error coming from third party like Script error., promise rejection not handle, how can i avoid and don't capture these kind of error

```auto
import { isServer } from '@utils/appAgent'

function checkApmError(err: any) {
    return err && err.message && err.message.indexOf('Script error') !== -1 ? true : false
}

export default function logError(e: any) {
    const errorObject = {
        result: 'error',
        errorStack: e.stack,
        rootURL: window.location.href,
        errorMessage: e.message
    }

    setTimeout(() => {
        // eslint-disable-next-line
        if (e.message && e.message !== 'Network Error' && !(e.message.indexOf('failed with status') > -1)) {
            if (typeof newrelic == 'object') {
                newrelic.addPageAction('pwa-error-ssr', {
                    result: 'error',
                    errorStack: e.stack,
                    rootURL: window.location.href,
                    errorMessage: e.message
                })
            }

            if (!isServer() && window?.apm && checkApmError(e) ) {
                window?.apm.captureError(new Error(JSON.stringify(errorObject)));
            }
        }
        console.error(e)
    })
}

```

 ![Screenshot 2024-04-24 at 12.42.42 PM](https://us1.discourse-cdn.com/elastic/original/3X/2/9/29764cf036d6e8b82be77a223200dd701d028e90.png)

I am using Nextjs, "@elastic/apm-rum": "^5.16.0",, macos

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [April 25, 2024, 9:33am UTC](https://discuss.elastic.co/t/there-are-some-error-coming-from-third-party/358095/2 "2024-04-25T09:33:32Z")

</div>

Hi @Maheta_Hemendra_Bhav,

You can implement a filter on the RUM agent to exclude particular payloads by returning false if it matches a criteria you want to exclude:

> **[Agent API | APM Real User Monitoring JavaScript Agent Reference \[5.x\] | Elastic](https://www.elastic.co/guide/en/apm/agent/rum-js/5.x/agent-api.html#apm-add-filter)**

Hope that helps!
