@oystehr/sdk
Version:
Oystehr SDK
59 lines (56 loc) • 1.54 kB
JavaScript
'use strict';
class OystehrSdkError extends Error {
code;
constructor({ message, code, cause }) {
super(message, { cause });
Object.setPrototypeOf(this, OystehrSdkError.prototype);
this.code = code;
this.name = 'OystehrSdkError';
}
toString() {
return `${this.name}: ${this.message} (code: ${this.code})`;
}
toJSON() {
return {
name: this.name,
message: this.message,
code: this.code,
cause: this.cause,
};
}
}
function transformOperationOutcomeToErrorMessage(cause) {
const causes = [];
for (const issue of cause.issue ?? []) {
if (issue.details && issue.details.text) {
causes.push(issue.details.text);
}
}
if (!causes.length) {
causes.push('Unknown FHIR error');
}
return causes.join(',');
}
class OystehrFHIRError extends OystehrSdkError {
cause;
constructor({ error, code }) {
super({
message: transformOperationOutcomeToErrorMessage(error),
code,
});
Object.setPrototypeOf(this, OystehrFHIRError.prototype);
this.cause = error;
this.name = 'OystehrFHIRError';
}
toJSON() {
return {
name: this.name,
message: this.message,
code: this.code,
cause: this.cause,
};
}
}
exports.OystehrFHIRError = OystehrFHIRError;
exports.OystehrSdkError = OystehrSdkError;
//# sourceMappingURL=index.cjs.map