# Error handling

There are different errors that could happen while using the WebLN APIs:

* User denies access to WebLN
* User cancels the process
* Connection errors
* Payment errors&#x20;

When an error happens during a WebLN API call the exception is thrown. Thus it is heavily recommended to handle different kinds of errors and let the user know what went wrong.&#x20;

```javascript
function pay() {
  if(typeof window.webln === 'undefined')
    return;
  
  try {
    await window.webln.enable();
    await window.webln.sendPayment(...);
  }
  catch(err) {
    console.log(error);
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.webln.guide/building-lightning-apps/webln-reference/error-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
