Skip to content

Error handling

The application throws nested errors, ranging from functional to technical. All errors extend SdsdkError.

Example of an invalid KAS credential error during encryption:

bash
[KasError: Unable to wrap DEK.] {
  cause: [InternalError: HTTP Error 401: Unauthorized - {"code":401,"message":"Kas Encrypt route call failed. Please contact your administrator.","details":"2001026,2006003,1014001,2005006"}] {
    cause: undefined,
    code: 'http'
  },
  code: 'wrap_dek'
}

Possible errors

The Stormshield SDK exposes the following errors:

Error class nameCodeDescription
UnwrapDekErrorThe DEK could not be unwrapped.
unwrap_dekThe DEK could not be unwrapped.
KasErrorAn error happened with the KAS that holds the KEK.
wrap_dekThe DEK could not be wrapped by the KAS.
unwrap_dek_splitA split of the DEK could not be retrieved.
unsupported_protocolThe requested protocol is not supported by the KAS.
invalid_kas_responseThe KAS responded, but the response format was unexpected.
invalid_kas_typeThe selected KAS type (remote, local) was not expected.
ConfigurationErrorThe configuration of Stormshield SDK instance is invalid.
kas_listThe kasList is invalid.
mappingThe mapping is invalid.
KasSelectionErrorThe resolution of the selection of one or several KASes in the KasList failed.
no_kao_matches_default_kasThe provided ZTDF does not includes the default KAS in its keyAccess.
no_kas_mapping_matches_data_attributesThe mapping of DataAttributes matched a value that is not present in the mapping configuration.
kas_does_not_support_protocolThe selected KAS does not support the requested protocol.
no_kas_matches_requested_protocolNo KAS in the Kaslist or in the resolved mapping selection supports the requested protocol.
AuthorizationErrorThe KAS Policy Decision Point (PDP) explicitely forbids the DEK decryption (ABAC mecanism).
dek_unwrapping_forbidden_by_pdpThe KAS Policy Decision Point (PDP) explicitely forbids the decryption of the DEK.
IntegrityErrorThe integrity of the ZTDF could not be verified.
invalid_assertions_integrityThe integrity of the assertions could not be verified. The ZTDF may have been manually modified.
invalid_root_signatureThe integrity of the data could not be verified. The ZTDF may have been manually modified.
ValidationErrorA validation failed.
invalid_ztdfThe ZTDF is invalid.
invalid_user_inputSome user input is invalid.
invalidA validation failed.
CryptographicErrorA local cryptographic operation failed.
data_decryptionThe decryption of data failed.
data_encryptionThe encryption of data failed.
dek_encryptionThe encryption of the DEK failed.
dek_decryptionThe decryption of the DEK failed.
rewrap_keypair_generationThe rewrap keypair generation failed.
signA signature operation failed.
hashA hash generation failed.
verifyA signature or hash verification failed.
unsupported_algorithmThe requested cryptographic algorithm is not supported.
random_generatorA random generation failed.
uuid_generatorA UUID generation failed.
parse_pemAn attempt to parse PEM failed.
InternalErrorLow level errors, generally not needed for user.
json_canonicalizationThe JSON canonicalization failed.
unexpectedSomething unexpected happened.
parsingA parsing operation failed.
httpAn outgoing HTTP request responded with not ok code.
networkA network issue prevents communication. Check network connectivity.
invalid_execution_environmentThe javascript runtime did not provide necessary dependencies (fetch, crypto).

Get error in the chain by code

You can assign custom logic for errors:

  • by using instanceof narrowing.
  • by using the findCode method to find if any error in the chain has a code.
typescript
import { readFile } from 'node:fs/promises';
import { AuthorizationErrorCodes, ValidationError, SdsdkError, Ztdf } from 'sdsdk';

try {
  const ztdf = await readFile('encrypt-result.ztdf');
  const sdsdkZtdf = await Ztdf.fromZip(ztdf);
  const result = await sdsdkInstance.decrypt(sdsdkZtdf);
} catch (error) {
  console.log(error); // whole error chain

  if (error instanceof ValidationError) {
    // your custom logic for any root ValidationError
  }

  const sdkError = error as SdsdkError; // cast or narrow as SdsdkError
  if (sdkError.findCode(AuthorizationErrorCodes.DekUnwrappingForbiddenByPDP)) {
    // your custom logic for code dek_unwrapping_forbidden_by_pdp anywhere in the chain
  }
}