fix(core): Surface enterprise trial error message (#10267)

This commit is contained in:
Iván Ovejero 2024-08-02 12:01:10 +02:00 committed by GitHub
parent 42ba8841c4
commit 432ac1da59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {
@ -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);
} else {
throw new BadRequestError('Failed to request trial');
}
}
}
@Post('/activate')