@@ -11,7 +11,7 @@ import { defaultInterfaces } from "./stack/builtins";
1111import { format } from "../format/index" ;
1212import { ContentType } from "../types/schema" ;
1313import { cliux } from "@contentstack/cli-utilities" ;
14- import { createErrorDetails } from "./shared/utils" ;
14+ import { createValidationError , createErrorDetails } from "./shared/utils" ;
1515
1616export const generateTS = async ( {
1717 token,
@@ -28,13 +28,8 @@ export const generateTS = async ({
2828} : GenerateTS ) => {
2929 try {
3030 if ( ! token || ! tokenType || ! apiKey || ! environment || ! region ) {
31- throw createErrorDetails (
32- {
33- type : "validation" ,
34- error_message :
35- "Please provide all the required params (token, tokenType, apiKey, environment, region)" ,
36- } ,
37- "generateTS"
31+ throw createValidationError (
32+ "Please provide all the required params (token, tokenType, apiKey, environment, region)"
3833 ) ;
3934 }
4035
@@ -65,13 +60,8 @@ export const generateTS = async ({
6560 "Please create Content Models to generate type definitions" ,
6661 { color : "yellow" }
6762 ) ;
68- throw createErrorDetails (
69- {
70- type : "validation" ,
71- error_message :
72- "There are no Content Types in the Stack, please create Content Models to generate type definitions" ,
73- } ,
74- "generateTS"
63+ throw createValidationError (
64+ "There are no Content Types in the Stack, please create Content Models to generate type definitions"
7565 ) ;
7666 }
7767
@@ -101,10 +91,9 @@ export const generateTS = async ({
10191 } catch ( error : any ) {
10292 if ( error . type === "validation" ) {
10393 // Handle validation errors with proper error codes
104- const errorDetails = createErrorDetails ( error , "generateTS" ) ;
10594 throw {
106- error_message : errorDetails . error_message ,
107- error_code : errorDetails . error_code ,
95+ error_message : error . error_message ,
96+ error_code : error . error_code || "VALIDATION_ERROR" ,
10897 } ;
10998 } else {
11099 const errorObj = JSON . parse ( error . message . replace ( "Error: " , "" ) ) ;
@@ -193,7 +182,7 @@ export const generateTSFromContentTypes = async ({
193182
194183 return output ;
195184 } catch ( err : any ) {
196- // Use common error details creation function
185+ // Use common function to create detailed error information
197186 const errorDetails = createErrorDetails ( err , "generateTSFromContentTypes" ) ;
198187
199188 // Don't log the error here - let the CLI handle the display
0 commit comments