Skip to content

Commit 703b14d

Browse files
authored
feat: update status response handling for portal generation (#232)
What was added? - Updated portal generation checks for new status response body.
1 parent 51e3ec2 commit 703b14d

4 files changed

Lines changed: 80 additions & 64 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $ npm install -g @apimatic/cli
2424
$ apimatic COMMAND
2525
running command...
2626
$ apimatic (--version)
27-
@apimatic/cli/1.1.0-beta.5 win32-x64 node-v23.4.0
27+
@apimatic/cli/1.1.0-beta.6 win32-x64 node-v23.4.0
2828
$ apimatic --help [COMMAND]
2929
USAGE
3030
$ apimatic COMMAND

package-lock.json

Lines changed: 61 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"test": "tsx node_modules/mocha/bin/_mocha --forbid-only \"test/**/*.test.ts\" --timeout 99999"
4848
},
4949
"dependencies": {
50-
"@apimatic/sdk": "^0.2.0-alpha.5",
50+
"@apimatic/sdk": "^0.2.0-alpha.6",
5151
"@clack/prompts": "1.0.0-alpha.1",
5252
"@oclif/core": "^4.2.8",
5353
"@oclif/plugin-autocomplete": "^3.2.24",

src/infrastructure/services/portal-service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
TransformationController,
1414
Transformation,
1515
ExportFormats,
16-
Platforms
16+
Platforms,
17+
Status
1718
} from "@apimatic/sdk";
1819
import { AuthInfo, getAuthInfo } from "../../client-utils/auth-manager.js";
1920
import { parseStreamBodyToJson } from "../../utils/utils.js";
@@ -58,6 +59,7 @@ export class PortalService {
5859
generationId = portalInstance.result.id;
5960
} catch (error) {
6061
if (error instanceof ProblemDetailsError) {
62+
// TODO: This only picks the first error message, improve it to show all errors.
6163
const message = Object.values(error.result!.errors as Record<string, string[]>)[0]?.[0] ?? null;
6264
const errorMessage = error.result!.title + "\n- " + message;
6365
if (error.statusCode === 400) {
@@ -85,10 +87,22 @@ export class PortalService {
8587
if (statusResult.isErr()) {
8688
return err(statusResult.error);
8789
}
88-
if (statusResult.value.status === "Failed") {
90+
if (statusResult.value.status === Status.Failed) {
8991
return err(ServiceError.ServerError);
9092
}
91-
} while (statusResult.value.status !== "Completed");
93+
if (statusResult.value.errors && statusResult.value.status === Status.ValidationError) {
94+
// TODO: This only picks the first error message, improve it to show all errors.
95+
const message = Object.values(statusResult.value.errors as Record<string, string[]>)[0]?.[0] ?? null;
96+
const errorMessage = "One or more validation errors occurred." + "\n- " + message;
97+
return err(ServiceError.badRequest(errorMessage));
98+
}
99+
if (statusResult.value.errors && statusResult.value.status === Status.SubscriptionError) {
100+
// TODO: This only picks the first error message, improve it to show all errors.
101+
const message = Object.values(statusResult.value.errors as Record<string, string[]>)[0]?.[0] ?? null;
102+
const errorMessage = "Access denied to resource." + "\n- " + message;
103+
return err(ServiceError.forbidden(errorMessage));
104+
}
105+
} while (statusResult.value.status !== Status.Completed);
92106

93107
try {
94108
const portalDownloadResponse = await docsPortalAsyncController.downloadGeneratedPortal(generationId);

0 commit comments

Comments
 (0)