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

(feat) OA-41: openmrsFetch() should handle redirects #1231

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
8 changes: 8 additions & 0 deletions packages/framework/esm-api/src/openmrs-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ export function openmrsFetch<T = any>(path: string, fetchInit: FetchConfig = {})
const response = r as FetchResponse<T>;
if (response.ok) {
if (response.status === 204) {
const { followRedirects } = await getConfig('@openmrs/esm-api');
if (followRedirects && response.headers.has('location')) {
const location = response.headers.get('location');
if (location) {
navigate({ to: location });
}
}

/* HTTP 204 - No Content
* We should not try to download the empty response as json. Instead,
* we return null since there is no response body.
Expand Down
5 changes: 5 additions & 0 deletions packages/framework/esm-api/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export function setupApiModule() {
"Changes how requests that fail authentication are handled. Try messing with this if redirects to the login page aren't working correctly.",
},
},
followRedirects: {
_type: Type.Boolean,
_default: true,
_description: 'Whether openmrsFetch should support redirects returned from the backend',
},
});

refetchCurrentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Error.constructor

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:296](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L296)
[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)

## API Properties

Expand All @@ -63,7 +63,7 @@ Error.constructor

#### 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)
[packages/framework/esm-api/src/openmrs-fetch.ts:312](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L312)

___

Expand All @@ -73,7 +73,7 @@ ___

#### 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)
[packages/framework/esm-api/src/openmrs-fetch.ts:313](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L313)

___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:310](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L310)
[packages/framework/esm-api/src/openmrs-fetch.ts:318](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L318)

___

Expand All @@ -47,7 +47,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/openmrs-fetch.ts:309](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L309)
[packages/framework/esm-api/src/openmrs-fetch.ts:317](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/openmrs-fetch.ts#L317)

___

Expand Down
Loading