@@ -104,3 +104,47 @@ test("getGitHubVersion for GHE_DOTCOM", async (t) => {
104104 } ) ;
105105 t . deepEqual ( { type : util . GitHubVariant . GHE_DOTCOM } , gheDotcom ) ;
106106} ) ;
107+
108+ test ( "wrapApiConfigurationError correctly wraps specific configuration errors" , ( t ) => {
109+ // We don't reclassify arbitrary errors
110+ const arbitraryError = new Error ( "arbitrary error" ) ;
111+ let res = api . wrapApiConfigurationError ( arbitraryError ) ;
112+ t . is ( res , arbitraryError ) ;
113+
114+ // Same goes for arbitrary errors
115+ const configError = new util . ConfigurationError ( "arbitrary error" ) ;
116+ res = api . wrapApiConfigurationError ( configError ) ;
117+ t . is ( res , configError ) ;
118+
119+ // If an HTTP error doesn't contain a specific error message, we don't
120+ // wrap is an an API error.
121+ const httpError = new util . HTTPError ( "arbitrary HTTP error" , 456 ) ;
122+ res = api . wrapApiConfigurationError ( httpError ) ;
123+ t . is ( res , httpError ) ;
124+
125+ const httpNotFoundError = new util . HTTPError ( "commit not found" , 404 ) ;
126+ res = api . wrapApiConfigurationError ( httpNotFoundError ) ;
127+ t . deepEqual ( res , new util . ConfigurationError ( "commit not found" ) ) ;
128+
129+ const refNotFoundError = new util . HTTPError (
130+ "ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest" ,
131+ 404 ,
132+ ) ;
133+ res = api . wrapApiConfigurationError ( refNotFoundError ) ;
134+ t . deepEqual (
135+ res ,
136+ new util . ConfigurationError (
137+ "ref 'refs/heads/jitsi' not found in this repository" ,
138+ ) ,
139+ ) ;
140+
141+ const apiRateLimitError = new util . HTTPError (
142+ "API rate limit exceeded for installation" ,
143+ 403 ,
144+ ) ;
145+ res = api . wrapApiConfigurationError ( apiRateLimitError ) ;
146+ t . deepEqual (
147+ res ,
148+ new util . ConfigurationError ( "API rate limit exceeded for installation" ) ,
149+ ) ;
150+ } ) ;
0 commit comments