|
| 1 | +--- |
| 2 | +id: errors |
| 3 | +title: RPC Errors |
| 4 | +description: "Understand common RPC errors and how to handle them." |
| 5 | +--- |
| 6 | + |
| 7 | +Understand common RPC errors and how to handle them. |
| 8 | + |
| 9 | +## What Could Go Wrong? |
| 10 | + |
| 11 | +When API request fails, RPC server returns a structured error response with a |
| 12 | +limited number of well-defined error variants, so client code can exhaustively |
| 13 | +handle all the possible error cases. Our JSON-RPC errors follow |
| 14 | +[verror](https://github.com/joyent/node-verror) convention for structuring |
| 15 | +the error response: |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "error": { |
| 20 | + "name": <ERROR_TYPE>, |
| 21 | + "cause": { |
| 22 | + "info": {..}, |
| 23 | + "name": <ERROR_CAUSE> |
| 24 | + }, |
| 25 | + "code": -32000, |
| 26 | + "data": String, |
| 27 | + "message": "Server error" |
| 28 | + }, |
| 29 | + "id": "dontcare", |
| 30 | + "jsonrpc": "2.0" |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +> **Heads up** |
| 35 | +> |
| 36 | +> The fields `code`, `data`, and `message` in the structure above are considered |
| 37 | +> legacy ones and might be deprecated in the future. Please, don't rely on them. |
| 38 | +
|
| 39 | +Here is the exhaustive list of the error variants that can be returned, organized by HTTP status code: |
| 40 | + |
| 41 | +## 200 - Successful Response with Error Data |
| 42 | + |
| 43 | +These errors occur when the request was processed successfully but the requested data could not be retrieved or an operation could not be completed due to various blockchain-related conditions. |
| 44 | + |
| 45 | +**ERROR_TYPE:** `HANDLER_ERROR` |
| 46 | + |
| 47 | +### General Errors |
| 48 | + |
| 49 | +These are general errors that can occur across different API endpoints. |
| 50 | + |
| 51 | +| ERROR_CAUSE | Reason | Solution | |
| 52 | +| ----------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 53 | +| UNKNOWN_BLOCK | The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node) | • Check that the requested block is legit <br/>• If the block had been produced more than 5 epochs ago, try to send your request to [an archival node](https://near-nodes.io/intro/node-types#archival-node) | |
| 54 | +| INVALID_ACCOUNT | The requested `account_id` is invalid | • Provide a valid `account_id` | |
| 55 | +| UNKNOWN_ACCOUNT | The requested `account_id` has not been found while viewing since the account has not been created or has been already deleted | • Check the `account_id` <br/>• Specify a different block or retry if you request the latest state | |
| 56 | +| UNAVAILABLE_SHARD | The node was unable to found the requested data because it does not track the shard where data is present | • Send a request to a different node which might track the shard | |
| 57 | +| NO_SYNCED_BLOCKS | The node is still syncing and the requested block is not in the database yet | • Wait until the node finish syncing <br/>• Send a request to a different node which is synced | |
| 58 | +| NOT_SYNCED_YET | The node is still syncing and the requested block is not in the database yet | • Wait until the node finish syncing <br/>• Send a request to a different node which is | |
| 59 | + |
| 60 | +### Access Keys |
| 61 | + |
| 62 | +Errors specific to [Access Keys API](/api/rpc/access-keys). |
| 63 | + |
| 64 | +| ERROR_CAUSE | Reason | Solution | |
| 65 | +| ------------------ | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | |
| 66 | +| UNKNOWN_ACCESS_KEY | The requested `public_key` has not been found while viewing since the public key has not been created or has been already deleted | • Check the `public_key` <br/>• Specify a different block or retry if you request the latest state | |
| 67 | + |
| 68 | +### Accounts / Contracts |
| 69 | + |
| 70 | +Errors specific to [Accounts / Contracts API](/api/rpc/contracts). |
| 71 | + |
| 72 | +| ERROR_CAUSE | Reason | Solution | |
| 73 | +| ------------------------ | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 74 | +| NO_CONTRACT_CODE | The account does not have any `contract` deployed on it | • Use different account <br/>• Specify a different block or retry if you request the latest state | |
| 75 | +| TOO_LARGE_CONTRACT_STATE | The requested contract state is too large to be returned from this node (the default limit is 50kb of state size) | • Send the request to a node with larger limits in order to view the requested state <br/>• Spin up your own node where you can increase the limits to view state | |
| 76 | +| CONTRACT_EXECUTION_ERROR | The execution of the view function call failed (crashed, run out of the default 200 TGas limit, etc) | • Check `error.cause.info` for more details | |
| 77 | + |
| 78 | +### Block / Chunk |
| 79 | + |
| 80 | +Errors specific to [Block / Chunk API](/api/rpc/block-chunk). |
| 81 | + |
| 82 | +| ERROR_CAUSE | Reason | Solution | |
| 83 | +| ---------------- | ------------------------------------------------------------------ | ---------------------------------------------------------------------- | |
| 84 | +| UNKNOWN_CHUNK | The requested chunk is not available or has been garbage-collected | • Check chunk ID validity <br/>• Try an archival node for older chunks | |
| 85 | +| INVALID_SHARD_ID | The provided shard ID is invalid or doesn't exist | • Provide a valid shard ID within the network's shard range | |
| 86 | + |
| 87 | +### Network |
| 88 | + |
| 89 | +Errors specific to [Network API](/api/rpc/network). |
| 90 | + |
| 91 | +| ERROR_CAUSE | Reason | Solution | |
| 92 | +| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 93 | +| UNKNOWN_EPOCH | An epoch for the provided block can't be found in a database | • Check that the requested block is legit <br/>• If the block had been produced more than 5 epochs ago, try to send your request to an archival node <br/>•Check that the requested block is the last block of some epoch | |
| 94 | + |
| 95 | +### Transactions |
| 96 | + |
| 97 | +Errors specific to [Transactions API](/api/rpc/transactions). |
| 98 | + |
| 99 | +| ERROR_CAUSE | Reason | Solution | |
| 100 | +| ------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 101 | +| INVALID_TRANSACTION | An error happened during transaction execution | • See `error.cause.info` for details, likely a field in the transaction was invalid <br/>•If `error.cause.info` is `ShardCongested`, resubmit the identical transaction after a delay. (Consider adding a priority fee once [NEP-541](https://github.com/near/NEPs/pull/541) is released.) <br/>• If `error.cause.info` is `ShardStuck`, you may also resubmit the identical transaction after a delay | |
| 102 | +| UNKNOWN_RECEIPT | The receipt with the given `receipt_id` was never observed on the node | • Check the provided `receipt_id` is correct <br/>• Send a request on a different node | |
| 103 | + |
| 104 | +## 400 - Bad Request |
| 105 | + |
| 106 | +These errors indicate that the request was malformed or contains invalid parameters that prevent the server from processing it. |
| 107 | + |
| 108 | +**ERROR_TYPE:** `REQUEST_VALIDATION_ERROR` |
| 109 | + |
| 110 | +| ERROR_CAUSE | Reason | Solution | |
| 111 | +| ----------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | |
| 112 | +| PARSE_ERROR | Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.) | • Check the arguments passed and pass the correct ones <br/>• Check `error.cause.info` for more details | |
| 113 | + |
| 114 | +## 408 - Request Timeout |
| 115 | + |
| 116 | +These errors occur when a request takes too long to process and times out before completion. |
| 117 | + |
| 118 | +**ERROR_TYPE:** `REQUEST_VALIDATION_ERROR` |
| 119 | + |
| 120 | +### Transaction Timeouts |
| 121 | + |
| 122 | +Errors specific to [Transactions API](/api/rpc/transactions) that occur due to timeout conditions. |
| 123 | + |
| 124 | +| ERROR_CAUSE | Reason | Solution | |
| 125 | +| ------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 126 | +| TIMEOUT_ERROR | Transaction was routed, but has not been recorded on chain in 10 seconds. | • Resubmit the request with the identical transaction (in NEAR Protocol unique transactions apply exactly once, so if the previously sent transaction gets applied, this request will just return the known result, otherwise, it will route the transaction to the chain once again) <br/>• Check that your transaction is valid <br/>• Check that the signer account id has enough tokens to cover the transaction fees (keep in mind that some tokens on each account are locked to cover the storage cost) | |
| 127 | + |
| 128 | +## 500 - Internal Server Error |
| 129 | + |
| 130 | +These errors indicate that something went wrong on the server side, typically due to internal issues or server overload. |
| 131 | + |
| 132 | +**ERROR_TYPE:** `INTERNAL_ERROR` |
| 133 | + |
| 134 | +| ERROR_CAUSE | Reason | Solution | |
| 135 | +| -------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | |
| 136 | +| INTERNAL_ERROR | Something went wrong with the node itself or overloaded | • Try again later <br/>• Send a request to a different node <br/>• Check `error.cause.info` for more details | |
0 commit comments