@@ -32,11 +32,15 @@ export class ApexGuruAuthService {
3232 async initialize ( config : AuthConfig ) : Promise < void > {
3333 // Method 1: SF CLI org (alias or username) via --target-org flag
3434 if ( config . targetOrg ) {
35+ this . emitLogEvent ( LogLevel . Fine , `Authenticating with org: ${ config . targetOrg } ` ) ;
3536 try {
3637 const org = await Org . create ( { aliasOrUsername : config . targetOrg } ) ;
3738 this . connection = org . getConnection ( ) ;
39+ this . emitLogEvent ( LogLevel . Fine , `Successfully authenticated to org` ) ;
3840 return ;
39- } catch ( _err ) {
41+ } catch ( err ) {
42+ const errorMessage = err instanceof Error ? err . message : String ( err ) ;
43+ this . emitLogEvent ( LogLevel . Error , `Failed to authenticate with org '${ config . targetOrg } ': ${ errorMessage } ` ) ;
4044 throw new Error (
4145 `Failed to authenticate with org '${ config . targetOrg } '. ` +
4246 'Please verify the org alias/username and ensure you are authenticated:\n' +
@@ -47,10 +51,14 @@ export class ApexGuruAuthService {
4751 }
4852
4953 // Method 2: SF CLI default org (fallback)
54+ this . emitLogEvent ( LogLevel . Fine , 'No target org specified, using default org' ) ;
5055 try {
5156 const org = await Org . create ( { } ) ;
5257 this . connection = org . getConnection ( ) ;
53- } catch ( _err ) {
58+ this . emitLogEvent ( LogLevel . Fine , 'Successfully authenticated to default org' ) ;
59+ } catch ( err ) {
60+ const errorMessage = err instanceof Error ? err . message : String ( err ) ;
61+ this . emitLogEvent ( LogLevel . Error , `Failed to authenticate: No default org found: ${ errorMessage } ` ) ;
5462 throw new Error (
5563 'No default org found. Please either:\n' +
5664 ' 1. Set a default org: sf config set target-org <org-alias>\n' +
0 commit comments