Skip to content

Commit 9eb6643

Browse files
authored
fix: improve error message for failure (#148)
1 parent be2c393 commit 9eb6643

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/cli/commands/build.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export const UpdatePlanStep: React.FC<UpdatePlanStepProps> = ({
162162
setFellbackToUpdate(true);
163163
}
164164

165+
let localCredentialsMissing = false;
166+
let localApiError: string | undefined = undefined;
167+
165168
// If we are pulling the latest Tracking Plan (npx rudder-typer), or if there is no local
166169
// copy of the Tracking Plan (plan.json), then query the API for the latest Tracking Plan.
167170
let newTrackingPlan: RudderAPI.TrackingPlan | undefined = undefined;
@@ -182,9 +185,12 @@ export const UpdatePlanStep: React.FC<UpdatePlanStepProps> = ({
182185
} catch (error) {
183186
handleError(error as WrappedError);
184187
if (isWrappedError(error)) {
185-
setAPIError(error.description);
188+
localApiError = error.description;
189+
setAPIError(localApiError);
186190
} else {
187-
setAPIError('API request failed');
191+
const err = error as APIError;
192+
localApiError = err.message;
193+
setAPIError(localApiError);
188194
}
189195
}
190196

@@ -194,11 +200,29 @@ export const UpdatePlanStep: React.FC<UpdatePlanStepProps> = ({
194200
}
195201
} else {
196202
setFailedToFindToken(true);
203+
204+
localCredentialsMissing = true;
205+
const missingItems = [];
206+
if (!token) missingItems.push('API token');
207+
if (!email) missingItems.push('email');
208+
209+
const warningMessage = `Missing credentials: ${missingItems.join(' and ')}. Please run 'rudder-typer init' to set up your credentials.`;
210+
handleError(wrapError(warningMessage));
197211
}
198212
}
199213
newTrackingPlan = newTrackingPlan || previousTrackingPlan;
200214
if (!newTrackingPlan) {
201-
handleFatalError(wrapError('Unable to fetch Tracking Plan from local cache or API'));
215+
if (localCredentialsMissing) {
216+
handleFatalError(
217+
wrapError(
218+
"Authentication failed: API credentials missing. Run 'rudder-typer init' to set up your credentials.",
219+
),
220+
);
221+
} else if (localApiError) {
222+
handleFatalError(wrapError(`Unable to fetch Tracking Plan: ${localApiError}`));
223+
} else {
224+
handleFatalError(wrapError('Unable to fetch Tracking Plan from local cache or API'));
225+
}
202226
return null;
203227
}
204228

0 commit comments

Comments
 (0)