Skip to content

feat: export error types from the package root#1558

Open
buptliuhs wants to merge 1 commit into
box:mainfrom
buptliuhs:feat/export-error-types
Open

feat: export error types from the package root#1558
buptliuhs wants to merge 1 commit into
box:mainfrom
buptliuhs:feat/export-error-types

Conversation

@buptliuhs

Copy link
Copy Markdown

Summary

Re-export BoxApiError, BoxSdkError, and the RequestInfo / ResponseInfo
types from the package root so consumers can import them directly:

import { BoxApiError } from 'box-node-sdk';

Today the only way to reach BoxApiError is a deep, internal path:

import { BoxApiError } from 'box-node-sdk/lib/box/errors';

Motivation

BoxApiError is the error every consumer needs in order to handle API
failures — it carries the HTTP status, responseInfo, error code, request
id, etc. But it isn't exported from the entry point, so callers must reach
into box-node-sdk/lib/box/errors, an internal lib/ path.

Beyond ergonomics, that deep import can be a hazard when the bare package and
its subpaths are resolved differently by a bundler. For example, if
box-node-sdk is marked external (resolved at runtime) while a deep subpath
import (box-node-sdk/lib/box/errors) is bundled instead, two copies of the
BoxApiError class exist at runtime — the one the SDK throws and the one the
consumer's check references — so error instanceof BoxApiError silently
returns false. Importing from the root, a single specifier, sidesteps that.

Changes

  • src/index.ts:

    • export { BoxApiError, BoxSdkError } from './box';
    • export type { RequestInfo, ResponseInfo } from './box';

    (These are already exported from ./box via export * from './errors';
    this just surfaces them at the root.)

Compatibility

Additive, non-breaking — new exports only; no existing signatures change.

Note for maintainers

If src/index.ts is generated by box-codegen rather than hand-maintained,
I'm happy to move this into the generator/templates — please point me at the
right place.

BoxApiError, BoxSdkError and the RequestInfo/ResponseInfo types were only
reachable via the internal `box-node-sdk/lib/box/errors` path. Re-export them
from the package root so consumers can do:

    import { BoxApiError } from 'box-node-sdk';

Importing from the root instead of a deep `lib/` subpath also avoids
dual-class-instance problems in bundled/externalized setups (e.g. AWS Lambda
layers), where the bundled subpath copy and the runtime copy are different
constructors and `instanceof BoxApiError` silently returns false.

Additive, non-breaking.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@buptliuhs
buptliuhs requested a review from a team July 22, 2026 09:18
@CLAassistant

CLAassistant commented Jul 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants