Skip to content

Commit

Permalink
Merge pull request #71 from identity-com/feature/CVC-1163__add_shared…
Browse files Browse the repository at this point in the history
…_IDV_error_classes_to_the_credential-commons_library

Feature/cvc 1163  add shared idv error classes to the credential commons library
  • Loading branch information
saviogrossi authored Feb 13, 2019
2 parents 32df787 + a244776 commit 679dc27
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions src/errors/idvErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// These codes are passed in the 'name' value of the error object when the IDV-toolkit
// throws an error
const IDVErrorCodes = {
ERROR_IDV_UCA_MISSING_PROPERTY: 'error.idv.uca.missing.property',
ERROR_IDV_UCA_NO_RETRIES: 'error.idv.uca.no.retries',
ERROR_IDV_PROCESS_HAS_FINAL_STATUS: 'error.idv.process.has.final.status',
ERROR_IDV_UCA_HAS_FINAL_STATUS: 'error.idv.uca.has.final.status',
ERROR_IDV_UCA_BATCH_HAS_FINAL_STATUS: 'error.idv.uca.batch.has.final.status',
ERROR_IDV_CR_INVALID_CREDENTIAL_ITEM: 'error.idv.cr.invalid.credentialItem',
ERROR_IDV_CREDENTIAL_INVALID_SIGNATURE: 'error.idv.credential.invalid.signature',
ERROR_IDV_CR_ALREADY_SIGNED: 'error.idv.cr.already.signed',
ERROR_IDV_CR_MISSING_PROPERTY: 'error.idv.cr.missing.property',
ERROR_IDV_UCA_SERVER: 'error.idv.uca.server',
ERROR_IDV_MISSING_UCA: 'error.idv.missing.uca',
ERROR_IDV_UCA_WRONG_VERSION: 'error.idv.uca.wrong.version',
ERROR_IDV_UCA_INVALID_EVENT: 'error.idv.uca.invalid.event',
ERROR_IDV_MISSING_PROCESS: 'error.idv.missing.process',
ERROR_IDV_MISSING_PLAN: 'error.idv.missing.plan',
ERROR_IDV_UCA_BAD_VALUE: 'error.idv.uca.bad.value',
ERROR_IDV_UCA_UPDATE_NO_STATUS: 'error.idv.uca.update.no.status',
ERROR_IDV_UCA_UPDATE_NO_PROCESS_STATUS: 'error.idv.uca.update.no.process.status',
ERROR_IDV_TOKEN_RECEIVED_BEFORE_ISSUE: 'error.idv.token.received.before.issue',
};

// these are used in the 'name' property in the array of objects passed as the errorContext
const ErrorContextTypes = {
MISSING_PROPERTY: 'missing_property',
UCA_STATE: 'uca_state',
UCA_VALUE: 'uca_value',
UCA_VERSION: 'uca_version',
PLAN_UCA_VERSION: 'plan_uca_version',
PROCESS_ID: 'process_id',
UCA_NAME: 'uca_name',
UCA_ID: 'uca_id',
CREDENTIAL_ITEM: 'credential_item',
UCA_ERROR: 'uca_error',
};

/*
* IDVError parses a HTTP Error response body from the IDV-toolkit
* Usage: the IDVError can be instantiated directly from the HTTPResponse body e.g.
* const idvError = new IDVError(response.body);
* @param errorObj: parsed directly from the HTTP Response body which should contain
* message: human readable explanation of the error e.g. 'Missing required UCA fields'
* name: Error-Code, defined in IDVErrorCodes, e.g. IDVErrorCodes.ERROR_IDV_UCA_MISSING_PROPERTY
* data: an array of objects with { name: "name", value: "value" } properties e.g.
* [{ name: ErrorContextType.MISSING_PROPERTY, value: missingProperty }]
* @returns an instance of IDVError
* */
class IDVError {
constructor(errorObj) {
this.message = errorObj.message;
this.errorCode = errorObj.name;
this.errorContext = errorObj.data;
}
}

module.exports = {
IDVErrorCodes,
ErrorContextTypes,
IDVError,
};
5 changes: 5 additions & 0 deletions src/errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const idvErrors = require('./idvErrors');

module.exports = {
idvErrors,
};
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const VC = require('./creds/VerifiableCredential');
const { initServices, services } = require('./services/index');
const isValidGlobalIdentifier = require('./isValidGlobalIdentifier');
const isClaimRelated = require('./isClaimRelated');
const errors = require('./errors');

/**
* Entry Point for Civic Credential Commons
* @returns {CredentialCommons}
Expand All @@ -15,6 +17,7 @@ function CredentialCommons() {
this.isValidGlobalIdentifier = isValidGlobalIdentifier;
this.isClaimRelated = isClaimRelated;
this.services = services;
this.errors = errors;
return this;
}

Expand Down

0 comments on commit 679dc27

Please sign in to comment.