@@ -13,7 +13,8 @@ import {
1313 TransformationController ,
1414 Transformation ,
1515 ExportFormats ,
16- Platforms
16+ Platforms ,
17+ Status
1718} from "@apimatic/sdk" ;
1819import { AuthInfo , getAuthInfo } from "../../client-utils/auth-manager.js" ;
1920import { 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