File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 99import { OptionsOfTextResponseBody } from 'got' ;
1010import got from 'got' ;
1111import { ProxyAgent } from 'proxy-agent' ;
12+ import { isString } from '@salesforce/ts-types' ;
13+ import { SfError } from '@salesforce/core' ;
1214import { CoverageObject } from '../../src/registry/types' ;
1315
1416const getProxiedOptions = ( url : string ) : OptionsOfTextResponseBody => ( {
@@ -31,9 +33,16 @@ let apiVer: number;
3133
3234export const getCurrentApiVersion = async ( ) : Promise < number > => {
3335 if ( apiVer === undefined ) {
34- const apiVersionsUrl = 'https://appexchange.salesforce.com/services/data' ;
35- const lastVersionEntry = ( await got ( getProxiedOptions ( apiVersionsUrl ) ) . json < ApiVersion [ ] > ( ) ) . pop ( ) as ApiVersion ;
36- apiVer = + lastVersionEntry . version ;
36+ try {
37+ const apiVersionsUrl = 'https://appexchange.salesforce.com/services/data' ;
38+ const lastVersionEntry = ( await got ( getProxiedOptions ( apiVersionsUrl ) ) . json < ApiVersion [ ] > ( ) ) . at ( - 1 ) as ApiVersion ;
39+ apiVer = + lastVersionEntry . version ;
40+ } catch ( e : unknown ) {
41+ const err = e instanceof Error ? e : SfError . wrap ( isString ( e ) ? e : 'unknown' ) ;
42+ const eMsg = 'Unable to get a current API version from the appexchange org' ;
43+ const eActions = [ 'Provide an API version explicitly' , 'Set an API version in the project configuration' ] ;
44+ throw new SfError ( eMsg , 'ApiVersionRetrievalError' , eActions , err ) ;
45+ }
3746 }
3847 return apiVer ;
3948} ;
You can’t perform that action at this time.
0 commit comments