# Error Handling

*For any API, if error occurs, it should return appropriate HTTP status code. Examples:*

* **401:** If user is not authenticated or session is expired
* **403:** If user is authenticated but does not have access to specified resource
* **404:** If the resource user is trying to access is not available

*Special handling for error codes:*

* **HTTP status code 401:** OpsHub will assume that authenticated session has been invalidated and call initialize API to re-login.
* **HTTP status code 403:** API should return this code when the API rate limit has been reached. OpsHub will wait for the time to come in `<HEADER1>` and resume after that, without failing the sync.

*Apart from the standard HTTP status code, API should also return the details of the errors if any custom error occurs during the processing of the request.*

* SDK should send end system code if any is returned from the end system.
  * For example: If the validation of the request payload is failed, API can return `400 (Bad Request)` response. The error response should also be sent along with the HTTP status.

## Error Response Payload

```json
{ 
  "errors": { 
    "code": "system-601", 
    "message": "Missing comment title", 
    "detail": "Title of the comment is required" 
  } 
}
```

| **Name** | **Required** | **Description**                                                                                                                                 |
| -------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| code     | True         | Error code sent by end system or specific code that SDK wants to send                                                                           |
| code     | True         | Detailed error message as to why API failed                                                                                                     |
| detail   | False        | It can contain error details like stack trace, end system response, etc. Anything SDK developer feels that will help the user resolve the 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://opstech.gitbook.io/opstech-docs/connector-sdk-index/sdk-connector-apis/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.
