Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Bug Fixes

- Expose Databricks API error codes on `ApiError.errorCode` while retaining `.code`.

### Documentation

### Internal Changes
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/apierror/apierror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class ApiError extends Error {
*/
readonly code: Code;

/** The Databricks error code returned by the API. */
readonly errorCode: Code;

/**
* The structured error details of the error. This is left empty if the
* error response is not a standard Databricks API error.
Expand All @@ -72,6 +75,7 @@ export class ApiError extends Error {
super(options.message, {cause: options.cause});
this.name = 'ApiError';
this.code = options.code;
this.errorCode = options.code;
this.details = options.details;
if (options.httpStatusCode !== undefined) {
this.httpErr = {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/tests/apierror/apierror.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('ApiError non-HTTP getters', () => {
it.each(testCases)(
'$name',
({apiErr, wantCode, wantMessage, wantDetails}) => {
expect(apiErr.errorCode).toBe(wantCode);
expect(apiErr.code).toBe(wantCode);
expect(apiErr.message).toBe(wantMessage);
expect(apiErr.details).toStrictEqual(wantDetails);
Expand Down Expand Up @@ -316,6 +317,7 @@ describe('fromHttpError', () => {
expect.fail('expected fromHttpError to return an ApiError');
}

expect(got.errorCode).toBe(tc.want.errorCode);
expect(got.code).toBe(tc.want.code);
expect(got.message).toBe(tc.want.message);
expect(got.details).toStrictEqual(tc.want.details);
Expand Down
Loading