# Responses and errors

Each command will return a response that may contain an `error` object in case of error.

- **One command at a time.** A command sent while another is still in flight is rejected with `-1 busy`. Serialise your commands, or wait for each response before sending the next.
- The `id` may be sent as a JSON number; it is always returned as a **string**. Correlate responses with the `id` you sent.
- A request whose `jsonrpc` is not `"2.0"`, or which carries no `method`, is rejected with `-32600 invalid.request`.

## Success

```json
{
  "jsonrpc": "2.0",
  "result": {},
  "id": "1"
}
```

## Error

The `message` is always the error's dotted identifier from the table below, sent verbatim.

```json
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32601,
    "message": "method.not.found"
  },
  "id": "1"
}
```

## Generic errors for all RNC commands

[www.jsonrpc.org/specification#error\_object](https://www.jsonrpc.org/specification#error_object)

```kotlin
EMPTY_LIST(
        -9,
        "empty.list"
    ),
    NULL_PARAMS(
        -8,
        "null.params"
    ),
    APPLICATION_NOT_STARTED(
        -7,
        "application.not.started"
    ),
    NOT_AUTHORIZED_IN_LICENCE(
        -6,
        "not.authorized.in.licence"
    ),
    UNEXPECTED_VARIANT_ERROR(
        -5,
        "unexpected.variant.error"
    ),
    EXCEPTION_CASTING_PARAMS(
        -4,
        "exception.casting.params"
    ),

    /**
     * RNC features are not available in this application
     */
    RNC_NOT_AVAILABLE(
        -3,
        "rnc.not.available"
    ),

    /**
     * The application is not yet ready to handle RNC commands (Core is not initialized)
     */
    APPLICATION_NOT_READY(
        -2,
        "application.not.ready"
    ),

    /**
     * The application is already handling a RNC command, this command is ignored
     */
    BUSY(
        -1,
        "busy"
    ),

    /**
     * An error occurred during Core initialization, application features are not available
     */
    CORE_INIT_ERROR(
        0,
        "core.init.error"
    ),

    /**
     * An error occurred during the json rpc 2.0 parsing
     */
    PARSE_ERROR(
        -32700,
        "parse.error"
    ),

    /**
     * The parsed command is not compliant with json rpc 2.0 standard
     */
    INVALID_REQUEST(
        -32600,
        "invalid.request"
    ),

    /**
     * The command's method is not supported
     */
    UNSUPPORTED_METHOD(
        -32601,
        "method.not.found"
    ),

    /**
     * Parameters of parsed command are invalid
     */
    INVALID_PARAMS(
        -32602,
        "invalid.params"
    ),

    /**
     * Unexpected internal error
     */
    INTERNAL_ERROR(
        -32603,
        "internal.error"
    ),
```

## Error codes

Every command may answer with one of these errors, read from the list above.

| Code | Message | Meaning |
|---|---|---|
| `-9` | `empty.list` |  |
| `-8` | `null.params` |  |
| `-7` | `application.not.started` |  |
| `-6` | `not.authorized.in.licence` |  |
| `-5` | `unexpected.variant.error` |  |
| `-4` | `exception.casting.params` |  |
| `-3` | `rnc.not.available` | RNC features are not available in this application |
| `-2` | `application.not.ready` | The application is not yet ready to handle RNC commands (Core is not initialized) |
| `-1` | `busy` | The application is already handling a RNC command, this command is ignored |
| `0` | `core.init.error` | An error occurred during Core initialization, application features are not available |
| `-32700` | `parse.error` | An error occurred during the json rpc 2.0 parsing |
| `-32600` | `invalid.request` | The parsed command is not compliant with json rpc 2.0 standard |
| `-32601` | `method.not.found` | The command's method is not supported |
| `-32602` | `invalid.params` | Parameters of parsed command are invalid |
| `-32603` | `internal.error` | Unexpected internal error |
