# Error codes

MMS API uses conventional HTTP response codes to indicate the success or failure of an API request:

* 2xx range indicates success
* 4xx range indicates client error. This means that the request is failed by given information provided (e.g., missed
required parameter, email is already used, wrong API Key)
* 5xx range indicates an error with EGYM servers (e.g., the server is unavailable, some internal error)


All 4xx errors could be handled programmatically. In case of these errors, error response will be returned.

### 400 Bad Request

This error indicates that the request cannot be accepted by the malformed request body. Some required fields are missing,
etc. In this case, we provide info in the response body with rejected or missing values. Usually comes with
default `"errorCode" : "invalidRequest"`

| errorCode | description |
|  --- | --- |
| invalidRequest | Generic code. Further details provided in the `message` field |
| invalidArguments | The request contains invalid arguments. Details is provided in the `errors` field, or in the `message` |


### 401 Unauthorized

API Key is missing. Check that `x-api-key` request header is present. See [Authentication](/mms-api-v2/authentication) for details.

### 403 Forbidden

Indicates that the request contains the wrong API key or is forbidden for some reason (for this case details could be found
in the error response body). See possible reasons in the table below:

| errorCode | description |
|  --- | --- |
| missingPermission | This action requires explicit permission. Please contact our support |
| forbiddenAction | Generic code. Further details provided in the `message` field |
| corporateFitnessMembershipExpired | The corporate fitness membership has expired |
| corporateFitnessMembershipNotStarted | The corporate fitness membership starts in the future |
| corporateFitnessGymNotInNetwork | The gym is not a network partner of the corporate fitness program |
| corporateFitnessGymNotInNetworkPlus1 | The gym is not participating in the Plus1 program, but the member has a Plus1 Corporate Fitness membership |


### 404 Not Found

The server can not find the requested resource. Check the URL path and identifiers provided in the request. Usually comes
with default `"errorCode" : "notFound"` and with metadata entity type. Response example:


```json
{
  "timestamp": "2023-04-11T14:35:48.499+0000",
  "path": "/api/v2/accounts",
  "status": 404,
  "error": "Not Found",
  "errorCode": "notFound",
  "message": "User's chain profile was not found.",
  "metadata": {
    "entity": "CHAIN_PROFILE"
  }
}
```

Possible entities:

| entity | description |
|  --- | --- |
| UNKNOWN | Used when the specific resource cannot be identified |
| ACCOUNT | Indicates that the server cannot find the EGYM account |
| CHAIN_PROFILE | Indicates that the server cannot find the chain profile of the specified EGYM account |
| MEMBERSHIP | Indicates that the server cannot find the membership |
| PRODUCT | Indicates that the server cannot find the product |
| WEBHOOK | Indicates that the server cannot find the webhook |
| GYM_LOCATION | Indicates that the server cannot find the specified gym location |
| TASK | Indicates that the server cannot find the specified task |
| RFID | Indicates that the server cannot find the specified RFID |
| NFC_TOKEN | Indicates that the server couldn't resolve the specified NFC |
| TAN | Indicates that the server cannot find the specified TAN |


### 409 Conflict

Indicates that the requested operation has a conflict with the current state of data.
See possible cases in the table below:

| errorCode | description |
|  --- | --- |
| userEmailConflict | The email is already used within your gym or chain |
| userEmailUsedByAnotherAccountConflict | The email is already used by another account |
| membershipExists | Action cannot be performed due to memberships conflict |
| tanAssociatedWithAnotherAccount | Provided tan is associated with another account |
| webhookUrlAlreadyRegistered | Given URL has already been registered for the current gym |
| generalConflict | Given resource already exists |
| forbiddenAccountMerge | Action blocked due to conflicting personal data with an existing account in the chain profile |


### 429 Too Many Requests

The user has sent too many requests in a given amount of time ("rate limiting"). You can retry the API call after a delay,
and increase the delay exponentially if the error continues.