@@ -46,15 +46,18 @@ class ExceptionGenerator {
4646 }
4747
4848 private final Integer bodyIndex ;
49+ private final Integer requestIndex ;
4950 private final Integer headerMapIndex ;
5051 private final Integer numOfParams ;
5152 private final Type bodyType ;
5253 private final Class <? extends Exception > exceptionType ;
5354 private final Decoder bodyDecoder ;
5455
55- ExceptionGenerator (Integer bodyIndex , Integer headerMapIndex , Integer numOfParams , Type bodyType ,
56+ ExceptionGenerator (Integer bodyIndex , Integer requestIndex , Integer headerMapIndex ,
57+ Integer numOfParams , Type bodyType ,
5658 Class <? extends Exception > exceptionType , Decoder bodyDecoder ) {
5759 this .bodyIndex = bodyIndex ;
60+ this .requestIndex = requestIndex ;
5861 this .headerMapIndex = headerMapIndex ;
5962 this .numOfParams = numOfParams ;
6063 this .bodyType = bodyType ;
@@ -72,6 +75,10 @@ Exception createException(Response response) throws InvocationTargetException,
7275 paramClasses [bodyIndex ] = Types .getRawType (bodyType );
7376 paramValues [bodyIndex ] = resolveBody (response );
7477 }
78+ if (requestIndex >= 0 ) {
79+ paramClasses [requestIndex ] = Request .class ;
80+ paramValues [requestIndex ] = response .request ();
81+ }
7582 if (headerMapIndex >= 0 ) {
7683 paramValues [headerMapIndex ] = response .headers ();
7784 paramClasses [headerMapIndex ] = Map .class ;
@@ -120,6 +127,7 @@ public ExceptionGenerator build() {
120127 Annotation [][] parametersAnnotations = constructor .getParameterAnnotations ();
121128
122129 Integer bodyIndex = -1 ;
130+ Integer requestIndex = -1 ;
123131 Integer headerMapIndex = -1 ;
124132 Integer numOfParams = parameterTypes .length ;
125133 Type bodyType = null ;
@@ -139,15 +147,22 @@ public ExceptionGenerator build() {
139147 }
140148 }
141149 if (!foundAnnotation ) {
142- checkState (bodyIndex == -1 ,
143- "Cannot have two parameters either without annotations or with @ResponseBody annotation" );
144- bodyIndex = i ;
145- bodyType = parameterTypes [i ];
150+ if (parameterTypes [i ].equals (Request .class )) {
151+ checkState (requestIndex == -1 ,
152+ "Cannot have two parameters either without annotations or with object of type feign.Request" );
153+ requestIndex = i ;
154+ } else {
155+ checkState (bodyIndex == -1 ,
156+ "Cannot have two parameters either without annotations or with @ResponseBody annotation" );
157+ bodyIndex = i ;
158+ bodyType = parameterTypes [i ];
159+ }
146160 }
147161 }
148162
149163 ExceptionGenerator generator = new ExceptionGenerator (
150164 bodyIndex ,
165+ requestIndex ,
151166 headerMapIndex ,
152167 numOfParams ,
153168 bodyType ,
0 commit comments