-
Notifications
You must be signed in to change notification settings - Fork 446
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
update UI errors for secrets on scripts and software #25008
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 16 additions & 10 deletions
26
frontend/pages/ManageControlsPage/Scripts/components/ScriptUploader/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { AxiosResponse } from "axios"; | ||
import { IApiError } from "interfaces/errors"; | ||
import { getErrorReason } from "interfaces/errors"; | ||
|
||
const UPLOAD_ERROR_MESSAGES = { | ||
default: { | ||
message: "Couldn’t upload. Please try again.", | ||
}, | ||
}; | ||
const DEFAULT_ERROR_MESSAGE = "Couldn't upload. Please try again."; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const getErrorMessage = (err: AxiosResponse<IApiError>) => { | ||
const apiReason = err.data.errors[0].reason; | ||
return apiReason || UPLOAD_ERROR_MESSAGES.default.message; | ||
export const getErrorMessage = (err: unknown) => { | ||
const apiErrMessage = getErrorReason(err); | ||
|
||
if ( | ||
apiErrMessage.includes( | ||
"File type not supported. Only .sh and .ps1 file type is allowed" | ||
) | ||
) { | ||
return "Couldn't upload. The file should be .sh or .ps1 file."; | ||
} else if (apiErrMessage.includes("Secret variable")) { | ||
return apiErrMessage.replace("missing from database", "doesn't exist"); | ||
} | ||
|
||
return apiErrMessage || DEFAULT_ERROR_MESSAGE; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,6 @@ const SoftwareCustomPackage = ({ | |
}; | ||
|
||
const onSubmit = async (formData: IPackageFormData) => { | ||
console.log("submit", formData); | ||
if (!formData.software) { | ||
renderFlash( | ||
"error", | ||
|
@@ -150,32 +149,7 @@ const SoftwareCustomPackage = ({ | |
</> | ||
); | ||
} catch (e) { | ||
const isTimeout = | ||
isAxiosError(e) && | ||
(e.response?.status === 504 || e.response?.status === 408); | ||
const reason = getErrorReason(e); | ||
|
||
if (isTimeout) { | ||
renderFlash( | ||
"error", | ||
`Couldn’t upload. Request timeout. Please make sure your server and load balancer timeout is long enough.` | ||
); | ||
} else if (reason.includes("Fleet couldn't read the version from")) { | ||
renderFlash( | ||
"error", | ||
<> | ||
{reason}{" "} | ||
<CustomLink | ||
newTab | ||
url={`${LEARN_MORE_ABOUT_BASE_LINK}/read-package-version`} | ||
text="Learn more" | ||
iconColor="core-fleet-white" | ||
/> | ||
</> | ||
); | ||
} else { | ||
renderFlash("error", getErrorMessage(e)); | ||
} | ||
renderFlash("error", getErrorMessage(e)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧼 |
||
} | ||
setUploadDetails(null); | ||
}; | ||
|
13 changes: 0 additions & 13 deletions
13
frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareCustomPackage/helpers.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareCustomPackage/helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import { isAxiosError } from "axios"; | ||
|
||
import { getErrorReason } from "interfaces/errors"; | ||
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants"; | ||
|
||
import CustomLink from "components/CustomLink"; | ||
|
||
const DEFAULT_ERROR_MESSAGE = "Couldn't add. Please try again."; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const getErrorMessage = (err: unknown) => { | ||
const isTimeout = | ||
isAxiosError(err) && | ||
(err.response?.status === 504 || err.response?.status === 408); | ||
const reason = getErrorReason(err); | ||
|
||
if (isTimeout) { | ||
return "Couldn't upload. Request timeout. Please make sure your server and load balancer timeout is long enough."; | ||
} else if (reason.includes("Fleet couldn't read the version from")) { | ||
return ( | ||
<> | ||
{reason}{" "} | ||
<CustomLink | ||
newTab | ||
url={`${LEARN_MORE_ABOUT_BASE_LINK}/read-package-version`} | ||
text="Learn more" | ||
iconColor="core-fleet-white" | ||
/> | ||
</> | ||
); | ||
} else if (reason.includes("Secret variable")) { | ||
return reason.replace("missing from database", "doesn't exist"); | ||
} | ||
|
||
return reason || DEFAULT_ERROR_MESSAGE; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
frontend/pages/SoftwarePage/SoftwareTitleDetailsPage/EditSoftwareModal/helpers.ts
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
frontend/pages/SoftwarePage/SoftwareTitleDetailsPage/EditSoftwareModal/helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from "react"; | ||
import { isAxiosError } from "axios"; | ||
|
||
import { getErrorReason } from "interfaces/errors"; | ||
import { ISoftwarePackage } from "interfaces/software"; | ||
|
||
import CustomLink from "components/CustomLink"; | ||
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants"; | ||
|
||
const DEFAULT_ERROR_MESSAGE = "Couldn't edit software. Please try again."; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const getErrorMessage = (err: unknown, software: ISoftwarePackage) => { | ||
const isTimeout = | ||
isAxiosError(err) && | ||
(err.response?.status === 504 || err.response?.status === 408); | ||
const reason = getErrorReason(err); | ||
|
||
if (isTimeout) { | ||
return "Couldn't upload. Request timeout. Please make sure your server and load balancer timeout is long enough."; | ||
} else if (reason.includes("Fleet couldn't read the version from")) { | ||
return ( | ||
<> | ||
Couldn't edit <b>{software.name}</b>. {reason}. | ||
<CustomLink | ||
newTab | ||
url={`${LEARN_MORE_ABOUT_BASE_LINK}/read-package-version`} | ||
text="Learn more" | ||
/> | ||
</> | ||
); | ||
} else if (reason.includes("selected package is")) { | ||
return ( | ||
<> | ||
Couldn't edit <b>{software.name}</b>. {reason} | ||
</> | ||
); | ||
} else if (reason.includes("Secret variable")) { | ||
return reason | ||
.replace("missing from database", "doesn't exist") | ||
.replace("Couldn't add", "Couldn't edit"); | ||
} | ||
|
||
return reason || DEFAULT_ERROR_MESSAGE; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this
else if
was removed? I added it back, but lmkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I mistakenly deleted this. Thanks for catching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ghernandez345 thanks for cleaning up the error code!!!