Errors
The error library
KCD comes with a great opinionated library that allows throwing error with status code translation, metadata, stack trace, logger ...
This error library provided with kcd allows us to:
Wrap errors
Known the previous domain calls if we use wrap correctly across our codebase
Attach a kind to the error (allow us to then translate the kind into HTTP status code)
Add metadata (i.e. fields)
Convert the error to logrus entry with stack trace ...
Print beautifully into the stack trace
Example
Default behavior:
if you throw this statement in your KCD handler you can expect the response below...
And a log that looks like this in your console:
Note that if the error is not an internal server error or an unknown error, the logger will not appear. If the logrus level is not in debug mode, the first stacktrace will not appear.
You can see the error handling in the error hook and the error logs in the log hook.
Format of the error message
The format of an error in KCD is the one that follows:
error_description
the human-readable description of the error (your error message)error
the error type (internal, invalid argument, forbidden, unauthorized ...)fields
if there is a validation error, it will set the key with the field name and the value with the message error for this fieldmetadata
currently only used to put the request-id if mentioned
Last updated