1
- function HttpError ( code , message ) {
1
+ function HttpError ( code , message , reqId ) {
2
2
this . code = code || 0
3
- this . message = message || ''
3
+ this . message = reqId ? ` ${ reqId } , ${ message || '' } ` : message || ''
4
4
}
5
5
6
6
HttpError . prototype = Error . prototype
@@ -25,37 +25,41 @@ function apiFactory(actions) {
25
25
actions . forEach ( ( action ) => {
26
26
apis [ action ] = async ( capi , inputs ) => {
27
27
inputs = cleanEmptyValue ( inputs )
28
- const res = await capi . request (
29
- {
30
- Action : action ,
31
- RequestClient : 'ServerlessComponent' ,
32
- Token : capi . options . Token || null ,
33
- ...inputs
34
- } ,
35
- {
36
- Version : '2017-03-12' ,
37
- ServiceType : 'cdn' ,
38
- bashHost : 'api.qcloud.com' ,
39
- path : '/v2/index.php'
28
+ try {
29
+ const { Response } = await capi . request (
30
+ {
31
+ Action : action ,
32
+ Version : '2018-06-06' ,
33
+ RequestClient : 'ServerlessComponent' ,
34
+ Token : capi . options . Token || null ,
35
+ ...inputs
36
+ } ,
37
+ {
38
+ debug : false ,
39
+ ServiceType : 'cdn' ,
40
+ host : 'cdn.tencentcloudapi.com'
41
+ }
42
+ )
43
+ if ( Response && Response . Error && Response . Error . Code ) {
44
+ throw new HttpError ( Response . Error . Code , Response . Error . Message , Response . RequestId )
40
45
}
41
- )
42
- if ( res . code !== 0 ) {
43
- throw new HttpError ( res . code , res . message )
46
+ return Response
47
+ } catch ( e ) {
48
+ throw new HttpError ( 500 , e . message )
44
49
}
45
- return res
46
50
}
47
51
} )
48
52
49
53
return apis
50
54
}
51
55
52
56
const ACTIONS = [
53
- 'AddCdnHost ' ,
54
- 'SetHttpsInfo ' ,
55
- 'GetHostInfoByHost ' ,
56
- 'DeleteCdnHost ' ,
57
- 'OfflineHost ' ,
58
- 'UpdateCdnConfig '
57
+ 'AddCdnDomain ' ,
58
+ 'DescribeDomains ' ,
59
+ 'UpdateDomainConfig ' ,
60
+ 'StopCdnDomain ' ,
61
+ 'DeleteCdnDomain ' ,
62
+ 'PurgeUrlsCache '
59
63
]
60
64
const APIS = apiFactory ( ACTIONS )
61
65
0 commit comments