Errors
Treat error codes as the stable contract. Human-readable messages can add context and may change; the code identifies the class of failure.
- TypeScript
- Go
try {
const document = parseDocument(value);
} catch (error) {
if (isKeyHoldError(error) && error.code === 'invalid_document') {
// Ask for a fresh document.
}
}
document, err := keyhold.Parse(data)
if err != nil {
switch keyhold.ErrorCodeOf(err) {
case keyhold.ErrInvalidDocument:
// Ask for a fresh document.
}
}
The stable categories are invalid_json, unsupported_format, unsupported_version, invalid_document, unsupported_algorithm, invalid_parameter, invalid_private_key, and unlock_failed.