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

fix: Allowed 404 to fall through axios during import flow #4770

Merged
merged 1 commit into from
Nov 11, 2020
Merged
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
24 changes: 13 additions & 11 deletions Composer/packages/client/src/components/ImportModal/ImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ export const ImportModal: React.FC<RouteComponentProps> = (props) => {
const res = await axios.post<{ alias: string; eTag: string; templateDir: string; urlSuffix: string }>(
`/api/import/${importSource}?payload=${encodeURIComponent(JSON.stringify(importPayload))}`
);
if (res.status !== 200) {
throw new Error(`Something went wrong during import: ${res.status} ${res.statusText}`);
}
const { alias, eTag, templateDir, urlSuffix } = res.data;
const projectInfo = {
description,
Expand All @@ -153,9 +150,17 @@ export const ImportModal: React.FC<RouteComponentProps> = (props) => {

if (alias) {
// check to see if Composer currently has a bot project corresponding to the alias
const aliasRes = await axios.get<any>(`/api/projects/alias/${alias}`);
const aliasRes = await axios.get<any>(`/api/projects/alias/${alias}`, {
validateStatus: (status) => {
// a 404 should fall through
if (status === 404) {
return true;
}
return status >= 200 && status < 300;
},
});
if (aliasRes.status === 200) {
const project = await aliasRes.data;
const project = aliasRes.data;
setExistingProject(project);
// ask user if they want to save to existing, or save as a new project
setModalState('promptingToSave');
Expand All @@ -165,7 +170,7 @@ export const ImportModal: React.FC<RouteComponentProps> = (props) => {
importAsNewProject(projectInfo);
} catch (e) {
// something went wrong, abort and navigate to the home page
console.error(`Aborting import: ${e}`);
console.error(`Something went wrong during import: ${e}`);
navigate('/home');
}
}
Expand All @@ -178,16 +183,13 @@ export const ImportModal: React.FC<RouteComponentProps> = (props) => {
if (modalState === 'signingIn') {
const signIn = async () => {
try {
const res = await axios.post(
await axios.post(
`/api/import/${importSource}/authenticate?payload=${encodeURIComponent(JSON.stringify(importPayload))}`
);
if (res.status !== 200) {
throw new Error(`Something went wrong during authenticating import: ${res.status} ${res.statusText}`);
}
setModalState('downloadingContent');
} catch (e) {
// something went wrong, abort and navigate to the home page
console.error(`Aborting import: ${e}`);
console.error(`Something went wrong during authenticating import: ${e}`);
navigate('/home');
}
};
Expand Down