Skip to content

Commit

Permalink
Fix 301 and 302 redirects.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed May 3, 2024
1 parent 6303bf4 commit be08164
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/components/theme/View/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ class View extends Component {
if (this.props.error && this.props.error.code === 301) {
const redirect = flattenToAppURL(this.props.error.url).split('?')[0];
return <Redirect to={`${redirect}${this.props.location.search}`} />;
} else if (this.props.error && this.props.error.status === 302) {
const redirect = flattenToAppURL(
this.props.error.response.header.location,
).split('?')[0];
return <Redirect to={`${redirect}${this.props.location.search}`} />;
} else if (this.props.error && !this.props.connectionRefused) {
let FoundView;
if (this.props.error.status === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Api {
) => {
let request;
let promise = new Promise((resolve, reject) => {
request = superagent[method](formatUrl(path));
request = superagent[method](formatUrl(path)).redirects(0);

if (params) {
request.query(params);
Expand Down
14 changes: 8 additions & 6 deletions src/helpers/Api/Api.plone.rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Api from './Api';

jest.mock('superagent', () => ({
get: jest.fn((url) => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
redirects: jest.fn(() => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
})),
})),
}));

Expand Down
14 changes: 8 additions & 6 deletions src/helpers/Api/Api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Api from './Api';

jest.mock('superagent', () => ({
get: jest.fn((url) => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
redirects: jest.fn(() => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
})),
})),
}));

Expand Down

0 comments on commit be08164

Please sign in to comment.