Result Codes - nonduality345/Convos GitHub Wiki

Result Codes

Result codes are domain specific codes that are used in the application internally to indicate the outcome of certain operations. These codes can then be used to make specific domain level decisions within the application in a clean, programmatic way, but I also choose to send them back to the client of the API as a way of keeping the information as transparent as possible to the client. Sometimes it may be the case that the result code can convey more information than just the Http Status code. For example, the codes 2 (ENTITY_NOT_FOUND) and 3 (NO_RESULTS) both result in a 404 (Not Found) status code, however, one indicates that only a singular resource is missing and the other indicates that a list of resources are missing. This is a very small (and probably insignificant) example, but in a larger API, we could have the flexibility of creating result codes that are much more specific than what can be conveyed in an Http Status code. Below are the result codes in the system:

  • OK = 0

    Everything behaved as expected. Nothing went wrong.

  • INVALID_INPUT_DATA = 1

    The input into the operation was invalid

  • ENTITY_NOT_FOUND = 2

    The specific entity that was requested could not be found

  • NO_RESULTS = 3

    There were no results from the operation

  • UNAUTHORIZED = 4

    The caller is unauthorized to perform the operation

  • CREATED = 5

    A new resource was created as a result of the operation

  • DELETED = 6

    A resource was deleted as a result of the operation

  • UNKNOWN = 7

    The operation did not behave as expected and the reason for it is not known