Exceptions in the backend can be thrown in two ways, however the first one is recommended:

  1. Using ApiErrorCode enum (recommended):
ApiErrorCode.DEVICES_001.throwException()
  1. With throw keyword:
throw DeviceNotFoundException("Device with given id not found")

When you decide to add create new exception in the backend, you have to add it to the ApiErrorCode enum, as well as to the following table. Make sure your new exception extends RestException base class in the following way:

class YourNewException(msg: String) : RestException(msg, HttpStatus.RETURNED_HTTP_CODE)

All exceptions returned from REST API have following format:

{
    "status": "NOT_FOUND",
    "message": "Device with given id not found",
    "code": "DEVICES_001",
    "timestamp": "2021-02-28T13:41:41.978123"
}

"code" field can be looked up in the following table to gain more knowledge about the exception:

REST Exceptions