diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ac0c08..311daac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Revert - -- Use old app-store-seller major for client - ### Fixed -- Use new app-store-seller major for client -- Shows error message when an API call request didn't complete, such as in a Timeout +- Handle non-JSON error messages in submit 400 responses instead of crashing the CLI ## [1.1.0] - 2021-11-22 diff --git a/src/lib/constants/Messages.ts b/src/lib/constants/Messages.ts index 42c2fe5..01cd729 100644 --- a/src/lib/constants/Messages.ts +++ b/src/lib/constants/Messages.ts @@ -11,6 +11,10 @@ export const Messages = { APP_NOT_INSTALLED: "The app you're trying to submit must be installed on this workspace.", + + VALIDATION_FAILED_UNKNOWN_REASON: + 'Your submission could not be validated. Make sure your app is both published and deployed before running `vtex submit`, then try again. If the problem persists, contact VTEX support.', + ENTER_GITHUB_USERNAME: 'Enter your Github username', ENTER_STATUS_CHECK_URL: 'Enter a URL from where we can test your app working. It can be in your workspace', diff --git a/src/modules/submit.ts b/src/modules/submit.ts index 99ed28e..7ae45b4 100644 --- a/src/modules/submit.ts +++ b/src/modules/submit.ts @@ -14,7 +14,20 @@ const handleSubmitAppError = (e: any) => { switch (status) { case 400: { - logger.error(Messages.OBJECT_FORMAT, JSON.parse(response?.data?.message)) + try { + logger.error( + Messages.OBJECT_FORMAT, + JSON.parse(response?.data?.message) + ) + } catch { + // response.data.message isn't valid JSON (e.g. an upstream service propagated + // a raw error string instead of a structured validation payload). Surface a + // clear, actionable message instead of letting the SyntaxError bubble up raw. + logger.error( + response?.data?.message ?? Messages.VALIDATION_FAILED_UNKNOWN_REASON + ) + } + break }