@@ -46,15 +46,17 @@ 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 , Integer numOfParams , Type bodyType ,
5657 Class <? extends Exception > exceptionType , Decoder bodyDecoder ) {
5758 this .bodyIndex = bodyIndex ;
59+ this .requestIndex = requestIndex ;
5860 this .headerMapIndex = headerMapIndex ;
5961 this .numOfParams = numOfParams ;
6062 this .bodyType = bodyType ;
@@ -72,6 +74,10 @@ Exception createException(Response response) throws InvocationTargetException,
7274 paramClasses [bodyIndex ] = Types .getRawType (bodyType );
7375 paramValues [bodyIndex ] = resolveBody (response );
7476 }
77+ if (requestIndex >= 0 ) {
78+ paramClasses [requestIndex ] = Request .class ;
79+ paramValues [requestIndex ] = response .request ();
80+ }
7581 if (headerMapIndex >= 0 ) {
7682 paramValues [headerMapIndex ] = response .headers ();
7783 paramClasses [headerMapIndex ] = Map .class ;
@@ -120,6 +126,7 @@ public ExceptionGenerator build() {
120126 Annotation [][] parametersAnnotations = constructor .getParameterAnnotations ();
121127
122128 Integer bodyIndex = -1 ;
129+ Integer requestIndex = -1 ;
123130 Integer headerMapIndex = -1 ;
124131 Integer numOfParams = parameterTypes .length ;
125132 Type bodyType = null ;
@@ -139,15 +146,22 @@ public ExceptionGenerator build() {
139146 }
140147 }
141148 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 ];
149+ if (parameterTypes [i ].equals (Request .class )) {
150+ checkState (requestIndex == -1 ,
151+ "Cannot have two parameters either without annotations or with object of type feign.Request" );
152+ requestIndex = i ;
153+ } else {
154+ checkState (bodyIndex == -1 ,
155+ "Cannot have two parameters either without annotations or with @ResponseBody annotation" );
156+ bodyIndex = i ;
157+ bodyType = parameterTypes [i ];
158+ }
146159 }
147160 }
148161
149162 ExceptionGenerator generator = new ExceptionGenerator (
150163 bodyIndex ,
164+ requestIndex ,
151165 headerMapIndex ,
152166 numOfParams ,
153167 bodyType ,
0 commit comments