11const { cns } = require ( 'tencent-cloud-sdk' ) ;
2- const { TypeError } = require ( '../../utils/error' ) ;
2+ const { ApiError } = require ( '../../utils/error' ) ;
33const { getRealType } = require ( '../../utils' ) ;
44
55class Cns {
@@ -116,11 +116,20 @@ class Cns {
116116 tempInputs . Action = 'RecordModify' ;
117117 try {
118118 const modifyResult = await this . cnsClient . request ( tempInputs ) ;
119- if ( modifyResult . code != 0 ) {
120- throw new TypeError ( `API_CNS_RecordModify` , JSON . stringify ( modifyResult ) ) ;
119+ if ( modifyResult . code !== 0 ) {
120+ throw new ApiError ( {
121+ type : `API_CNS_RecordModify` ,
122+ message : modifyResult . message ,
123+ code : modifyResult . code ,
124+ } ) ;
121125 }
122126 } catch ( e ) {
123- throw new TypeError ( `API_CNS_RecordModify` , e . message , e . stack ) ;
127+ throw new ApiError ( {
128+ type : `API_CNS_RecordModify` ,
129+ message : e . message ,
130+ stack : e . stack ,
131+ code : e . code ,
132+ } ) ;
124133 }
125134 console . log ( `Modified dns record ${ tempInputs . recordId } success` ) ;
126135 } else {
@@ -129,13 +138,22 @@ class Cns {
129138 tempInputs . Action = 'RecordCreate' ;
130139 try {
131140 let createOutputs = await this . cnsClient . request ( tempInputs ) ;
132- if ( createOutputs . code != 0 ) {
133- throw new TypeError ( `API_CNS_RecordCreate` , JSON . stringify ( createOutputs ) ) ;
141+ if ( createOutputs . code !== 0 ) {
142+ throw new ApiError ( {
143+ type : `API_CNS_RecordCreate` ,
144+ message : createOutputs . message ,
145+ code : createOutputs . code ,
146+ } ) ;
134147 }
135148 createOutputs = createOutputs [ 'data' ] ;
136149 tempInputs . recordId = createOutputs . record . id ;
137150 } catch ( e ) {
138- throw e ;
151+ throw new ApiError ( {
152+ type : `API_CNS_RecordCreate` ,
153+ message : e . message ,
154+ stack : e . stack ,
155+ code : e . code ,
156+ } ) ;
139157 }
140158 console . log ( `Created dns record ${ tempInputs . recordId } ` ) ;
141159 }
@@ -160,11 +178,20 @@ class Cns {
160178 } ;
161179 try {
162180 const statusResult = await this . cnsClient . request ( statusInputs ) ;
163- if ( statusResult . code != 0 ) {
164- throw new TypeError ( `API_CNS_RecordStatus` , JSON . stringify ( statusResult ) ) ;
181+ if ( statusResult . code !== 0 ) {
182+ throw new ApiError ( {
183+ type : `API_CNS_RecordStatus` ,
184+ message : statusResult . message ,
185+ code : statusResult . code ,
186+ } ) ;
165187 }
166188 } catch ( e ) {
167- throw new TypeError ( `API_CNS_RecordStatus` , e . message , e . stack ) ;
189+ throw new ApiError ( {
190+ type : `API_CNS_RecordStatus` ,
191+ message : e . message ,
192+ stack : e . stack ,
193+ code : e . code ,
194+ } ) ;
168195 }
169196 console . log ( `Modified status to ${ tempInputs . status } ` ) ;
170197 }
@@ -187,7 +214,7 @@ class Cns {
187214 } ;
188215 try {
189216 const deleteResult = await this . cnsClient . request ( deleteInputs ) ;
190- if ( deleteResult . code != 0 ) {
217+ if ( deleteResult . code !== 0 ) {
191218 console . log ( `Error API_CNS_RecordDelete: ${ JSON . stringify ( deleteResult ) } ` ) ;
192219 }
193220 } catch ( e ) {
0 commit comments