Errors ====== Every error response has the same JSON body, so a client can handle errors in one place. The error object ---------------- .. code-block:: json {"error": "not_found", "message": "no such device"} ``error`` A stable code. Programs act on it. ``message`` An explanation for people. It never quotes tokens, keys or values sent by the client. Do not parse it: the text may change. ``acr_values`` Only with ``insufficient_user_authentication``: the ``acr`` the action needs. Codes ----- .. list-table:: :header-rows: 1 :widths: 30 10 60 * - ``error`` - Status - Meaning * - ``bad_request`` - 400 - Malformed request: syntax, a missing field, a wrong parameter or cursor, a missing ``X-Org`` * - ``unauthorized`` - 401 - Missing, expired or wrong credential * - ``insufficient_user_authentication`` - 401 - The action needs a second factor (see :doc:`authentication`) * - ``forbidden`` - 403 - No permission, or not a member of ``X-Org`` * - ``not_found`` - 404 - Unknown, or not visible to the active organization * - ``conflict`` - 409 - Conflicts with the current state, for example a name that exists * - ``invalid_value`` - 422 - A value does not fit the data dictionary or a field definition * - ``too_many_pending`` - 429 - Too many commands that are not final for the device * - ``rate_limited`` - 429 - Too many requests; wait ``Retry-After`` seconds (see :doc:`rate-limits`) * - ``internal`` - 500 - Server error; retry later Order of the checks ------------------- Findy IoT Core checks a request in this order and answers with the first check that fails, so the response tells nothing beyond what the caller may know: #. authentication → 401 ``unauthorized``; #. ``X-Org``: membership, or the organization of the key → 403 ``forbidden``; #. the second factor of the active organization → 401 ``insufficient_user_authentication``; #. the permission of the operation → 403 ``forbidden``; #. the visibility of the resource (device, command, filter, key, organization, member, role, invite, relation) → 404 ``not_found``; #. the checks of the operation itself, for example the checks of a command (see :doc:`devices-data-commands`). How to handle errors -------------------- * 400, 404 and 422: fix the request. * 409: read the current state first, for example run the preview of a bulk action again. * 401: get a new credential; for ``insufficient_user_authentication`` sign in again with a second factor. * 403: the key or role lacks the permission named in ``x-permission`` of the operation. * 429: wait ``Retry-After`` seconds, or for ``too_many_pending`` until a command of the device is final. * 500: retry later. Example ------- A device that does not exist, or that your organization cannot see:: curl -i -H "Authorization: Bearer " \ https://console.example.com/api/v1/devices/123456789012347 :: HTTP/1.1 404 Not Found Content-Type: application/json Cache-Control: no-store {"error": "not_found", "message": "no such device"}