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

(chore) Add FetchError interface for more granular error typing #1230

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
7 changes: 6 additions & 1 deletion packages/framework/esm-api/src/openmrs-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function openmrsObservableFetch<T>(url: string, fetchInit: FetchConfig =
});
}

export class OpenmrsFetchError extends Error {
export class OpenmrsFetchError extends Error implements FetchError {
constructor(url: string, response: Response, responseBody: ResponseBody | null, requestStacktrace: Error) {
super();
this.message = `Server responded with ${response.status} (${response.statusText}) for url ${url}. Check err.responseBody or network tab in dev tools for more info`;
Expand Down Expand Up @@ -323,3 +323,8 @@ interface FetchBody {
export interface FetchResponseJson {
[key: string]: any;
}

export interface FetchError {
response: Response;
responseBody: ResponseBody | null;
}
12 changes: 12 additions & 0 deletions packages/framework/esm-framework/docs/classes/OpenmrsFetchError.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

↳ **`OpenmrsFetchError`**

## Implements

- [`FetchError`](../interfaces/FetchError.md)

## Table of contents

### API Constructors
Expand Down Expand Up @@ -61,6 +65,10 @@ Error.constructor

• **response**: `Response`

#### Implementation of

[FetchError](../interfaces/FetchError.md).[response](../interfaces/FetchError.md#response)

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:304](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L304)
Expand All @@ -71,6 +79,10 @@ ___

• **responseBody**: ``null`` \| `string` \| [`FetchResponseJson`](../interfaces/FetchResponseJson.md)

#### Implementation of

[FetchError](../interfaces/FetchError.md).[responseBody](../interfaces/FetchError.md#responsebody)

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:305](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L305)
Expand Down
34 changes: 34 additions & 0 deletions packages/framework/esm-framework/docs/interfaces/FetchError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[@openmrs/esm-framework](../API.md) / FetchError

# Interface: FetchError

## Implemented by

- [`OpenmrsFetchError`](../classes/OpenmrsFetchError.md)

## Table of contents

### API Properties

- [response](FetchError.md#response)
- [responseBody](FetchError.md#responsebody)

## API Properties

### response

• **response**: `Response`

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:328](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L328)

___

### responseBody

• **responseBody**: ``null`` \| `ResponseBody`

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:329](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L329)
Loading