Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-3306: Error class hierarchy #186

Merged
merged 10 commits into from
Jul 2, 2024
Merged

Conversation

NSeydoux
Copy link
Contributor

@NSeydoux NSeydoux commented Jul 1, 2024

This introduces the core classes for this library, namely:

  • InruptClientError, the superclass for all Inrupt client related errors,
  • ClientHttpError, the base class for HTTP errors

Note that classes for specific HTTP errors (Unauthenticated, Not Found...) are not included yet, and will be added later.

ClientHttpError extends the base InruptClientError by implementing two interfaces, WithProblemDetails and WithErrorResponse, respectively associated to their type guards hasProblemDetails and hasErrorResponse. Both the .problemDetails and .response accessors are marked as read-only, and immutability is enforced at runtime for libraries not using static analysis based on TS.

The constructor of ClientHttpError takes in a response body and a subset of the native Response metadata, instead of taking a simple Response instance, because reading the Response body is an asynchronous operation, which isn't possible when building an object. It is expected that the parsing will be done by the caller in an async context, and the result will be passed to the ClientHttpError constructor, which is not the initial design.

For the time being, I'm not doing any submodule exports (e.g. @inrupt/solid-client-error/http), but this is something we might eventually consider for tree-shaking.

This PR fixes bug #.

  • I've added a unit test to test for potential regressions of this bug.
  • The changelog has been updated, if applicable.
  • Commits in this PR are minimal and have descriptive commit messages.

New feature description

Checklist

  • All acceptance criteria are met.
  • Relevant documentation, if any, has been written/updated.
  • The changelog has been updated, if applicable.
  • New functions/types have been exported in index.ts, if applicable.
  • New elements of the public API have appropriate API docs (including @since and @example).
  • New modules (i.e. new .ts files) are listed in the exports field in package.json, if applicable.
  • New modules (i.e. new .ts files) are listed in the typedocOptions.entryPoints field in tsconfig.json, if applicable.
  • Commits in this PR are minimal and have descriptive commit messages.

This PR bumps the version to .

Release Steps

  1. Look at the CHANGELOG.md to determine whether the release should be a major, minor, or patch release. Coordinate with the team to ensure the next version is agreed upon.
  2. Run npm version -- <major|minor|patch> --no-push with the decided on version (to prevent the tag from being pushed).
  3. Update the CHANGELOG.md to release the latest the version, and set the release date.
  4. Commit the changes on a release/vX.Y.Z branch
  5. Push to GitHub, create a PR, and merge once CI passes.
  6. Create a release on GitHub for the new version, using a combination of the release notes from the CHANGELOG.md and the automatically generated changes.
    The release should have a new tag matching the new version number: vx.y.z, and point to the release commit.

This introduces the core classes for this library, namely:
- `InruptClientError`, the superclass for all Inrupt client related errors,
-  `ClientHttpError`, the base class for HTTP errors

Note that classes for specific HTTP errors (Unauthenticated, Not Found...) are not included yet, and will be added later.

`ClientHttpError` extends the base `InruptClientError` by implementing two interfaces, `WithProblemDetails` and `WithErrorResponse`, respectively associated to their type guards `hasProblemDetails` and `hasErrorResponse`. Both the `.problemDetails` and `.response` accessors are marked as read-only, and immutability is enforced at runtime for libraries not using static analysis based on TS.

The constructor of `ClientHttpError` takes in a response body and a subset of the native `Response` metadata, instead of taking a simple `Response` instance, because reading the `Response` body is an asynchronous operation, which isn't possible when building an object. It is expected that the parsing will be done by the caller in an async context, and the result will be passed to the `ClientHttpError` constructor, which is not the initial design.

For the time being, I'm not doing any submodule exports (e.g. `@inrupt/solid-client-error/http`), but this is something we might eventually consider for tree-shaking.
Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
solid-client-errors-js ❌ Failed (Inspect) Jul 1, 2024 3:33pm

@NSeydoux NSeydoux requested a review from a team as a code owner July 1, 2024 15:50
/**
* Superclass of all errors thrown by Inrupt's client libraries.
*
* @since unreleased
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it typical to use unreleased in this context? I am only wondering about the possibility of forgetting to set this to the right version before release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the approach we have taken with our other libraries, so that it's easier to search for on release. However, we also have in other places a checklist item specifically for this, which was missing here: a250e37.

src/http/httpError.test.ts Outdated Show resolved Hide resolved
src/http/httpError.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@edwardsph edwardsph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small suggestions

src/http/problemDetails.ts Outdated Show resolved Hide resolved
src/http/errorResponse.mock.ts Outdated Show resolved Hide resolved
src/http/problemDetails.mock.ts Outdated Show resolved Hide resolved
src/http/httpError.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@edwardsph edwardsph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested test change

src/http/httpError.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@edwardsph edwardsph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NSeydoux NSeydoux merged commit bbe9741 into main Jul 2, 2024
8 of 9 checks passed
@NSeydoux NSeydoux deleted the SDK-3306/error-class-hierarchy branch July 2, 2024 10:36
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.

3 participants