Skip to content

Commit bbe9741

Browse files
NSeydouxedwardsph
andauthored
SDK-3306: Error class hierarchy (#186)
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. Co-authored-by: Pete Edwards <[email protected]>
1 parent 3954f9f commit bbe9741

21 files changed

+1162
-22
lines changed

.eslintrc.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,22 @@ module.exports = {
2323
parserOptions: {
2424
project: "./tsconfig.eslint.json",
2525
},
26-
ignorePatterns: ["dist/"],
26+
overrides: [
27+
{
28+
rules: {
29+
// Conflicts with TS imports
30+
"import/no-unresolved": "off",
31+
"no-shadow": [
32+
"error",
33+
{
34+
// status is a (deprecated) global variable, but it also is the
35+
// conventional name for a Response attribute.
36+
allow: ["status"],
37+
},
38+
],
39+
},
40+
files: "*",
41+
},
42+
],
43+
ignorePatterns: ["dist/", "docs/"],
2744
};

.github/pull_request_template.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ This PR bumps the version to <version number>.
3030
1. Look at the [CHANGELOG.md](../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.
3131
2. Run `npm version -- <major|minor|patch> --no-push` with the decided on version (to prevent the tag from being pushed).
3232
3. Update the `CHANGELOG.md` to release the latest the version, and set the release date.
33-
4. Commit the changes on a `release/vX.Y.Z` branch
34-
5. Push to GitHub, create a PR, and merge once CI passes.
35-
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.
33+
4. Add the `@since X.Y.Z` annotations to new APIs.
34+
5. Commit the changes on a `release/vX.Y.Z` branch
35+
6. Push to GitHub, create a PR, and merge once CI passes.
36+
7. 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.
3637
The release should have a new tag matching the new version number: `vx.y.z`, and point to the release commit.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
docs/api/source/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ releases](https://nodejs.org/en/about/releases/), and support 18.x and 20.x.
4040

4141
# Installation
4242

43-
For the latest stable version of solid-client-error:
43+
For the latest stable version of solid-client-errors:
4444

4545
```bash
4646
npm install @inrupt/solid-client-errors

jest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import type { Config } from "jest";
2424
type ArrayElement<MyArray> = MyArray extends Array<infer T> ? T : never;
2525

2626
const baseConfig: ArrayElement<NonNullable<Config["projects"]>> = {
27+
coveragePathIgnorePatterns: [".*\\.mock\\.ts"],
2728
modulePathIgnorePatterns: ["dist/", "<rootDir>/examples/"],
29+
// Setup required because of missing globals in JSDom
30+
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
2831
testRegex: "/src/.*\\.test\\.ts$",
2932
clearMocks: true,
3033
injectGlobals: false,

jest.setup.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Copyright Inrupt Inc.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal in
6+
// the Software without restriction, including without limitation the rights to use,
7+
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
// Software, and to permit persons to whom the Software is furnished to do so,
9+
// subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
//
21+
22+
import "@inrupt/jest-jsdom-polyfills";

0 commit comments

Comments
 (0)