@@ -615,3 +615,92 @@ describe("CertificateError instance methods", () => {
615
615
expect ( allowInsecureSpy ) . toHaveBeenCalled ( ) ;
616
616
} ) ;
617
617
} ) ;
618
+
619
+ describe ( "Logger integration" , ( ) => {
620
+ it ( "should log certificate parsing errors through Logger" , async ( ) => {
621
+ const { logger :realLogger } = createMockOutputChannelWithLogger ( ) ;
622
+
623
+ // Create a logger that uses the real Logger
624
+ const loggerWrapper = {
625
+ writeToCoderOutputChannel :( msg :string ) => {
626
+ realLogger . info ( msg ) ;
627
+ } ,
628
+ } ;
629
+
630
+ // Create an axios error that will trigger certificate parsing
631
+ const axiosError = {
632
+ isAxiosError :true ,
633
+ code :X509_ERR_CODE . UNABLE_TO_VERIFY_LEAF_SIGNATURE ,
634
+ message :"unable to verify the first certificate" ,
635
+ } ;
636
+
637
+ // Mock CertificateError.determineVerifyErrorCause to throw an error
638
+ const determineVerifyErrorCauseSpy = vi
639
+ . spyOn ( CertificateError , "determineVerifyErrorCause" )
640
+ . mockRejectedValue ( new Error ( "Failed to parse certificate" ) ) ;
641
+
642
+ // Call maybeWrap which should log the parsing error
643
+ const result = await CertificateError . maybeWrap (
644
+ axiosError ,
645
+ "https://test.com" ,
646
+ loggerWrapper ,
647
+ ) ;
648
+
649
+ // Verify the error was logged
650
+ const logs = realLogger . getLogs ( ) ;
651
+ expect ( logs . length ) . toBe ( 1 ) ;
652
+ expect ( logs [ 0 ] . message ) . toBe (
653
+ "Failed to parse certificate from https://test.com: Error: Failed to parse certificate" ,
654
+ ) ;
655
+ expect ( logs [ 0 ] . level ) . toBe ( "INFO" ) ;
656
+
657
+ // Verify the original error was returned (not wrapped)
658
+ expect ( result ) . toBe ( axiosError ) ;
659
+
660
+ // Restore the spy
661
+ determineVerifyErrorCauseSpy . mockRestore ( ) ;
662
+ } ) ;
663
+
664
+ it ( "should work with Storage instance that has Logger set" , async ( ) => {
665
+ const { logger :realLogger } = createMockOutputChannelWithLogger ( ) ;
666
+
667
+ // Simulate Storage with Logger
668
+ const mockStorage = {
669
+ writeToCoderOutputChannel :( msg :string ) => {
670
+ realLogger . info ( msg ) ;
671
+ } ,
672
+ } ;
673
+
674
+ // Create an axios error that will trigger certificate parsing
675
+ const axiosError = {
676
+ isAxiosError :true ,
677
+ code :X509_ERR_CODE . UNABLE_TO_VERIFY_LEAF_SIGNATURE ,
678
+ message :"unable to verify the first certificate" ,
679
+ } ;
680
+
681
+ // Mock determineVerifyErrorCause to throw
682
+ const determineVerifyErrorCauseSpy = vi
683
+ . spyOn ( CertificateError , "determineVerifyErrorCause" )
684
+ . mockRejectedValue ( new Error ( "Certificate parsing failed" ) ) ;
685
+
686
+ // Call maybeWrap with the mockStorage
687
+ await CertificateError . maybeWrap (
688
+ axiosError ,
689
+ "https://example.com:8443" ,
690
+ mockStorage ,
691
+ ) ;
692
+
693
+ // Verify error was logged through Logger
694
+ const logs = realLogger . getLogs ( ) ;
695
+ expect ( logs . length ) . toBeGreaterThan ( 0 ) ;
696
+ const hasExpectedLog = logs . some ( ( log ) =>
697
+ log . message . includes (
698
+ "Failed to parse certificate from https://example.com:8443" ,
699
+ ) ,
700
+ ) ;
701
+ expect ( hasExpectedLog ) . toBe ( true ) ;
702
+
703
+ // Restore the spy
704
+ determineVerifyErrorCauseSpy . mockRestore ( ) ;
705
+ } ) ;
706
+ } ) ;