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(core): Surface enterprise trial error message #10267

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
15 changes: 14 additions & 1 deletion packages/cli/src/license/license.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Get, Post, RestController, GlobalScope } from '@/decorators';
import { AuthenticatedRequest, LicenseRequest } from '@/requests';
import { LicenseService } from './license.service';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import type { AxiosError } from 'axios';

@RestController('/license')
export class LicenseController {
Expand All @@ -14,7 +16,18 @@ export class LicenseController {
@Post('/enterprise/request_trial')
@GlobalScope('license:manage')
async requestEnterpriseTrial(req: AuthenticatedRequest) {
await this.licenseService.requestEnterpriseTrial(req.user);
try {
await this.licenseService.requestEnterpriseTrial(req.user);
} catch (error: unknown) {
if (error instanceof Error) {
const errorMsg =
(error as AxiosError<{ message: string }>).response?.data?.message ?? error.message;

throw new BadRequestError(errorMsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relying on the error message that the license server returns. Maybe we should update the license server to return error codes, so that we can map those to human readable errors in this repo, instead of having to update the license server every time product wants to change the error that gets displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relying on the error message that the license server returns.

This is in a workflow, but I agree with the general principle.

} else {
throw new BadRequestError('Failed to request trial');
}
}
}

@Post('/activate')
Expand Down
Loading