# mco_iot_conn_get_error

Receive the last error description.

### For an overview see page ARF Applications in C

### Prototype

        void mco_iot_conn_get_error(iot_connection_h iotc,
                        mco_iot_stop_reason_t *reason,
                        MCO_RET *last_error,
                        int *last_errno,
                        char *message,
                        int message_len);

### Arguments

iotc | The connection handle (`iot_connection_h`)
reason | One of the following enumerated values:
      typedef enum mco_iot_stop_reason_t_
      {
        MCO_IOT_STOP_REASON_NONE = 0,
        MCO_IOT_STOP_REASON_NETWORK_ERROR,
        MCO_IOT_STOP_REASON_CALLBACK_FAILED,
        MCO_IOT_STOP_REASON_IOT_STOPPED,
        MCO_IOT_STOP_REASON_USER_REQUEST

      } mco_iot_stop_reason_t;
last_error | The last error code; one of the MCO_E_* values
last_errno | The last network error code: only meaningful for network errors
message | The buffer to receive the error message text
message_len | The error message buffer size

### Description

This function receives the error description for the last error in the `onDisconnect()` and `onDestroy()` callbacks to find out why the connection was dropped.

### Return Codes

void | No value returned

### Example

        // onDisconnect callback
        int iot_on_disconnect(mco_iot_connection_h iotc, void *context)
        {
            char errmsg[128];
            mco_iot_stop_reason_t stop_reason;
            MCO_RET last_error;
            int last_errno;
            mco_iot_conn_get_error(iotc, &stop_reason, &last_error, &last_errno, errmsg, sizeof(errmsg));
            printf("IoT device %llu disconnected. Reason %d, errcode %d. errno %d : <%s>",
            mco_iot_conn_get_agent_id(iotc), stop_reason, last_error, last_errno, errmsg);
            return IOT_CALLBACK_OK;
        }

### Files

Header file:
mcoiot.h
Source file:
mcoiotcomm.c
Library:
libmcoiotcomm.a