Skip to content

The structure of errors

Vyatcheslav Suharnikov edited this page Jul 7, 2019 · 3 revisions

Error codes

An error is combined from three numbers:

  • An object code. It encodes an object which an error is addressed to. For example, it could be an order (the code is 9);
  • A part code. It is a part of object. For example, the fee with the 17 code;
  • An error class. For example, the notEnough with the 6 code;

An object and a part shares same codes and both called "entity".

The error's code formula is:

errorCode = (objectCode << 20) + (partCode << 8) + classCode

So, there are 11 bits for object's code (integers in JVM are signed), 12 bits for a part's code and 8 bits for a code of class.

You can extract any part from the error's code:

  • objectCode = (errorCode >> 20) & 0x7FF
  • partCode = (errorCode >> 8) & 0xFFF
  • classCode = errorCode & 0xFF

JSON

In a JSON representation of error you will see four fields:

  • error is the code of error;
  • template is the template of error's message. It contains parameters in double curly brackets like {{assetPair}};
  • params is a JSON object with all used in the template parameters. The JSON representation doesn't contain this field if there are no parameters;
  • message is the error's text, the result of params substitution to the template;

There is a simple rule what to show to the users:

  • If you develop a rich UI with a multi language support, use the template;
  • If you are not interested in support other languages, use message.

Also, do not rely on error's message/template/params in your code. They can be changed in the future. Use the error for this purposes!

Samples

A JSON without parameters:

{
  "template" : "System is starting",
  "error" : 13,
  "message" : "System is starting"
}

A JSON with the one parameters:

{
  "template" : "The order {{id}} is canceled",
  "error" : 9437194,
  "message" : "The order 4jSaBhDPm3 is canceled",
  "params" : {
    "id" : "4jSaBhDPm3"
  }
}

A JSON with nested parameters:

{
  "template" : "Trading is denied for the {{assetPair}} asset pair",
  "error" : 9440770,
  "message" : "Trading is denied for the BzgirMH-WAVES asset pair",
  "params" : {
    "assetPair" : {
      "amountAsset" : "BzgirMH",
      "priceAsset" : null
    }
  }
}

See

Also see an auto-generated list of all errors.

Sometimes you will see the strange error messages in the samples like: foo should be >= 5, but it is 5.

It's okay, because this part of documentation is generated automatically.

Clone this wiki locally