# Errors

PactFlow uses conventional HTTP response codes to indicate the success or failure of an API request. 

In general: 

* Codes in the `2xx` range indicate success. 
* Codes in the `4xx` range indicate an error that failed given the information provided (e.g., a required parameter was omitted, a charge failed, etc.). 
* Codes in the `5xx` range indicate an error with PactFlow's servers (these are rare).

## Extended Errors with Problem Details

When the `Accept` header includes `application/problem+json` media type, the "Problem Detail" error type as described in [RFC9457](https://www.rfc-editor.org/rfc/rfc9457.html) (formally RFC7808) communicate details about an error and is intended for use with HTTP status codes in the `4xx` and `5xx` series.

Example:

```
curl 
  -H"Accept: application/json, application/hal+json, application/problem+json" \
  -H"Authorization: Bearer <token>" \
  https://foo.pactflow.io/badpath  
```

This will result in an error like this:

```
{
  "title": "Validation errors",
  "type": "https://problems-registry.smartbear.com/validation-error",
  "status": 400,
  "instance": "/",
  "errors": [
    {
      "detail": "is missing",
      "pointer": "#/name"
    }
  ]
}
```

*NOTE: as is shown here, some resources contain the additional `errors` extension property containing an array of error messages.*

Without the `application/problem+json` header, a legacy format is used in one of the following formats:

```
{ "errors": ["message"]}
```

```
{ "error": "message" }
```

```
{ "errors": { "<key>": ["message"] }}
```

We consider the legacy format deprecated and will remove it in the next major version, therefore ***it is strongly recommended to opt-in to the Problem JSON error format.***

> To learn more about the types of `problem-details` that are possible, check out the [SmartBear Problem Details Registry](https://problems-registry.smartbear.com/)
