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 }