feat: export error types from the package root#1558
Open
buptliuhs wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-export
BoxApiError,BoxSdkError, and theRequestInfo/ResponseInfotypes from the package root so consumers can import them directly:
Today the only way to reach
BoxApiErroris a deep, internal path:Motivation
BoxApiErroris the error every consumer needs in order to handle APIfailures — it carries the HTTP status,
responseInfo, errorcode, requestid, etc. But it isn't exported from the entry point, so callers must reach
into
box-node-sdk/lib/box/errors, an internallib/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-sdkis marked external (resolved at runtime) while a deep subpathimport (
box-node-sdk/lib/box/errors) is bundled instead, two copies of theBoxApiErrorclass exist at runtime — the one the SDK throws and the one theconsumer's check references — so
error instanceof BoxApiErrorsilentlyreturns
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
./boxviaexport * 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.tsis 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.