@oystehr/sdk
Version:
Oystehr SDK
56 lines (54 loc) • 1.48 kB
JavaScript
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,
};
}
}
export { OystehrFHIRError, OystehrSdkError };
//# sourceMappingURL=index.js.map