├── .gitignore
├── .mvn
├── jvm.config
├── maven.config
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .settings.xml
├── .travis.yml
├── LICENSE
├── README.md
├── RELEASE.md
├── mvnw
├── pom.xml
├── src
├── config
│ ├── bom.xml
│ ├── eclipse-java-style.xml
│ └── pomSortOrder.xml
├── etc
│ └── header.txt
├── main
│ └── java
│ │ └── feign
│ │ └── error
│ │ ├── AnnotationErrorDecoder.java
│ │ ├── ErrorCodes.java
│ │ ├── ErrorHandling.java
│ │ ├── ExceptionGenerator.java
│ │ ├── FeignExceptionConstructor.java
│ │ ├── MethodErrorHandler.java
│ │ ├── ResponseBody.java
│ │ └── ResponseHeaders.java
└── test
│ └── java
│ └── feign
│ └── error
│ ├── AbstractAnnotationErrorDecoderTest.java
│ ├── AnnotationErrorDecoderClassInheritanceTest.java
│ ├── AnnotationErrorDecoderExceptionConstructorsTest.java
│ ├── AnnotationErrorDecoderIllegalInterfacesTest.java
│ ├── AnnotationErrorDecoderInheritanceTest.java
│ ├── AnnotationErrorDecoderNoAnnotationTest.java
│ ├── AnnotationErrorDecoderPriorityTest.java
│ └── TestPojo.java
└── travis
└── publish.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | target
3 | *.iml
--------------------------------------------------------------------------------
/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
--------------------------------------------------------------------------------
/.mvn/maven.config:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenFeign/feign-annotation-error-decoder/546752425238f3d42d0ceec91d5c5af05841803e/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
--------------------------------------------------------------------------------
/.settings.xml:
--------------------------------------------------------------------------------
1 |
16 |
20 |
21 |
22 | sonatype
23 | ${env.SONATYPE_USER}
24 | ${env.SONATYPE_PASSWORD}
25 |
26 |
27 | bintray
28 | ${env.BINTRAY_USER}
29 | ${env.BINTRAY_KEY}
30 |
31 |
32 | jfrog-snapshots
33 | ${env.BINTRAY_USER}
34 | ${env.BINTRAY_KEY}
35 |
36 |
37 | github.com
38 | ${env.GH_USER}
39 | ${env.GH_TOKEN}
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Run `travis lint` when changing this file to avoid breaking the build.
2 | # Default JDK is really old: 1.8.0_31; Trusty's is less old: 1.8.0_51
3 | # https://docs.travis-ci.com/user/ci-environment/#Virtualization-environments
4 | dist: trusty
5 | sudo: false
6 | language: java
7 | jdk: oraclejdk8
8 | before_install:
9 | # Parameters used during release
10 | - git config user.name "$GH_USER"
11 | - git config user.email "$GH_USER_EMAIL"
12 | # setup https authentication credentials, used by ./mvnw release:prepare
13 | - git config credential.helper "store --file=.git/credentials"
14 | - echo "https://$GH_TOKEN:@github.com" > .git/credentials
15 |
16 | install:
17 | # Override default travis to use the maven wrapper
18 | - ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip=true -B -V
19 |
20 | script:
21 | - ./travis/publish.sh
22 |
23 | cache:
24 | directories:
25 | - $HOME/.m2
26 |
27 |
28 | matrix:
29 | include:
30 | - os: linux
31 | jdk: oraclejdk8
32 | addons:
33 | apt:
34 | packages:
35 | - oracle-java8-installer
36 | #removing openjdk8 from matrix for now as it causes issues on release
37 | # - os: linux
38 | # jdk: openjdk8
39 | # - os: linux
40 | # jdk: openjdk11
41 |
42 | # Don't build release tags. This avoids publish conflicts because the version commit exists both on master and the release tag.
43 | # See https://github.com/travis-ci/travis-ci/issues/1532
44 | branches:
45 | except:
46 | - /^[0-9]/
47 |
48 | env:
49 | global:
50 | # Ex. travis encrypt BINTRAY_USER=your_github_account
51 | - secure: "UGCb+uE9a/hGVEPlAUM/iFgGYxnjJJ79nhl8a/RHsUJQI0/hGUwYkjELCVM3D9ck0hZI6xTjk/fr2JwTlAghmBYun8K9xKhGYnUShwCGwFBZzGRxLcN2Hfv2y4jSgUG59lRVxAFJFjXaH2wBooNmRRm/rjQpqdKiVissx6fUWq2B+zKUKQofXZlCi7gXTNeyQS4ROeDk3O+Q7uVLZ6ut39JSTSOl1t3AGBwJJ+Rz8d3kbLshM1T04MnRR7BRpDknWBc2b+7cbfNSRsQ8F7gbYce/lZSz5/WlE6c+RXNLztCf4AbPdkrJx5I6WRdCD34Hleo1zqTy2JOHneYJGKfupeqrvglFDibnJmsSpaOhgcGPCl5vi2MI/B0FiSyjtsdxgW9+ZaR3um3+6bBYfBznmPq379gCQcbxOX2+VlItSJHcOqH651F5akp58Uw7qO3bYYlj07pmZvZz//PaZf6F/h0LxLUGqn0esMBxLYsLb6nk8/DR5EL/69goR8qYkV17VHgTPNGT7YB7lQ+lQGzq9q7m9hT3lZj57ZjOrcHKTc0e9AA/8hOpMIegaeTHhRbrOUMQFWsqHke73BPKFvrJYEi54H4P1LatDCB1aQXoYuXsujR7idS6JGDW1kJy5ljppPjhzT9DYs4ypYI37yswSTrsQtwFysYC1FLVuklJCJU="
52 | # # Ex. travis encrypt BINTRAY_KEY=xxx-https://bintray.com/profile/edit-xxx --add
53 | - secure: "XpunNYBzavq6waWQFr0G6ixR1egdqjGq+EbIjGb3h/AvHkOPA6NAgthOgyZFnB3xSOTP6M8SVRFPZyC69zcA69n8Np1vfo1eKZjq6mKG+gpxh19x4zqhd57dlt1TITmqiuPqShwIfcDLWI8Tb8sQ4CiI71AGtFXo4c83Nll79eS+wxqwXqyGn643bt/7DjPeZx7GVKi1iippO+TJCxnBmlJEj9g2N/ynb2AE0ofmf66pCSVWUZQ7AF366j/pSWXe0Y8jLdMR9LkC1nvznjtxcM3Kc0SzYJqzWN/AzkkUndQBt30fLdTH1Se/TAMltaAXiYXHld7giJFAUY8RybIm6Zp21Gawd/MvHqsEg0KJ84OaIuxBAbWBKCn7Wp7r+VLqOEaJF7bzGc2BZgFCTcr2xN6Q4EIQboanKjEGQZ5DxaNC3gQeNTJRenUH+PAHrk6a1ZPaO24ymDYOaN9wyJo+ueJGXTCS8fjYZJNlTk93D/koftkUapvuU5rd+2w/Q4oL6D/7fPCyiH94C428+nEaYzTkpqibSU1tRG8zDxl+MkVTQ4t0dJfVH3Hz4eqXs+9mir69a2QmQuFoefSOr5fNa7m+Hx0/H0FvmzAqnrSkmlXXG6d3Y7YDUEPtgVeZ8CJ+qFLRalkWM9cV+7bDc+SWxM2vC0HsT6LNS+IHT36fYBQ="
54 | # # Ex. travis encrypt GH_USER_EMAIL=for_github@domain.com --add
55 | - secure: "WJQvlc3K9KWUHz71qqlgux1xH11Cz/IY3QaNDU6Zg5bsBwDMCS03WwNw/4JfmH89u55sXEYlmtC6i38WrZbjJy2peNOP62FVP7zyPagehACJW71Q2uoOs6OPQDmQsh6n+sFOxEBbl4zc8nD6QgAt/X3n7MO7BcHreokUHHOPz7hQ8KNiF1zK2r4h8/98gInP5wbw8TemUDJgFhFJbWSIENg3tfBOgypb+pjOCViHwqm4gBs2/S9IYBBNAf415KHvz7QvIU49JQFMrhMj89hX/mbywWFcBfbTqXVT3El6V7f5gN2A77nMxWeaFfoYvG3BBr4fcuf8AaRgHtL0twTTS5tMGx45RnhQGjTFMFvEPRRglh78TMIcgO688rFJmQCi8IY7mLEvTIHvI7BXrAz+A1xuhGyLyteopdOJsZ4e7AAOqwvdef3JQXgR3LCTsaevJfXIenMl4Lb5Eh/LIcEaxpZCSH2nuMOMDfn1lw4L7sMxCC1QjEs+hnuKE72DDZOyyT7co5aZlvcvglHOEEWyAuwpy08+LH8NKOluFia3+g2WdhrFZoxd/vNDc6SSBbYnAPVtn+v36ucDuP6N8snATs3VU5yjWePzfCVpbnclwBvc+kmGSGXqDTdQlQXLRLF9aAY5sLyECc921E/Jesz0t34ZU5poGBER+tH1WDeZIG0="
56 | # # Ex. travis encrypt GH_USER=your_github_account --add
57 | - secure: "g2NBlGFcPLtgPQByQGy9dequHtdVCs2tAx3lEIQJoYv7VTlv+sPHaLSn4/sSSPven9k4KCF9cMZ/mF4+TBJxfR+WhvbqVI+nL1js8dHw4ko7wGhNUMeZot0l6u44JtalNiYCA8+0sn8rrj9lisS/xE3kzpyXMVZ3CMEBBp5gghUUwjKTXJPnV/WcmTbari6MCCa8UVQ3G4J9prhjX9ZRFZSQGk+5MrRH+O/EqkThpEQaUDtOaXx3P8RMcO8KwpPs8GUD++Z9clnH2NTs24BRJ6oOdbyR+9KnmBIV/FOYCmSelBmBs5AznkPz3XRQfSW8CfFLepHkEWvjw9k1hHMvQTAtqz5ZJyvbVC0ztIK8O1q8bQAOBoHRkQyxWk5o/57SrwgSQTtYLjoAjsR4Et2Noab01qme8/Knd8XYhee46CnHtxpPq6dhX58CB9N0Tep4TJYz5pKfe5q8jAQO9ceaLiPAhnRNzpHN/2CksXTdbdp+/go9FU7sBs61q+JK29zbVQTNpgiLiNagoJ8ZP8JkVDklQWK++wCWb2PxiaTMgsGxfRt2qydnpLdA/qkUrov7vlNlt5EEXqSslo+jdMfSsDBhr442bYrUGzlzTAuZTqBk2hS9VXSktUvDwzdx84BRQ2iKyfmeeuHDWdzLeQ+C+gMtb+Z1j6RRN1Bzcxaja58="
58 | # # Ex. travis encrypt GH_TOKEN=XXX-https://github.com/settings/tokens-XXX --add
59 | - secure: "SYm90I0vUc9i52aISvGEgjlW3ACrAE6orzE08b2PAvKJqzcZ+3FOKvWpgAPDypXr+6LYiYhtOrX2Yt3S6/XDpizDQPcaz09aRBG3AR9yzDuE3UQgazPtgd2cNQiMIoKiBfIMi2z5jJk0PpYNxi0n7cOXSKBmxKjXCAcD4PUAZzR4hCYph1qWBtsj82WMqXgC6BxlLUPYYrnPALnyfmDxsYB017e2AyGkk7ItLWF90ov87d+BbulknOQ5fXp5atkV/xgcrr73yATe4pniWr8c2HZy1jaeYqtFYDN4QVhgN3QBrtGIwKYZbamYLgL5OX2g5L5JWqaR8RICZVs/5bQecwcNlHph8yRoByc/cssZhLnPbMgIbeSE02YbJ+Xk+kEtEBhSv6jGWlicWX8cl+d5Z0QRBKl+c/QrIuA1p7ltk5S4cb0WedPWu/u90eJZUoAb3HKpquAgU2FTohNby/Je8L+P+QtpmqOMk5cM+kformomx1bYEw2RQj+hj+G2fE8lvuZtXA1n45KAiCN185YI4/1Sdo9guBKdUjgs6ig37pJkbhVSsAdbfUUeb9wCVN2nOf2E2P19ZZoAJ0Gkf/zWGuNiFHcvLBORpZ9oIb3o6TeSi1rj8zJiGNmBzBXHZ2JDfgzfaabnnxpwUHtHBB0HA3uyA/xMJWuyAzeeRl9TorA="
60 | # # Ex. travis encrypt SONATYPE_USER=your_sonatype_account
61 | - secure: "JRkMiXYwDURgZFJg/pOT+jsd9JXq74tRUBaTbvvcvaOdpfL5tBjgdoQgu/xvDttcwF74v5ygOWrXBKM/Q4fLamMrX+Z2+s/fMawXgZC0DsIU3UWB4W0rg2IWW9ByLTRrEOmRs1kIIEG5IfpvwuviQPbIbeKdZL9yDmRikah4kWAy/cDiUF3oqieSfww8TSzkk1edh+LlWfiz3kyXFThV1kjN1emQxbRKR8onK9LqIBTsiaxuz0h+hJnUFvHIp13DzqMYzq4TE1LKerC3aj/GwAlbuJYnE0Qe++phEjVcr6tEVEkc2NbWfRywKFo0o7TqoEpHZI0olCRcwvRnUUU6OMlIHLa9N2P9u+LqJ4Y6Im+hcqIfPFG04BEww6fp6EkPWzGM2vv+uLADBEPT7Rxg95LWkC8JrFtRkT3JNah7O9LErLVmDW7cAh2lFeqaHgBWHXxqULdFrlh///pZIhQDClKvNF+fKWsFfPNqBEoa5a88dNDd5i3y10+XqIeo8BQNYUGDF4PmaOrxIcOPEmlAfaIR8ZI4U/t4LuxM6v57fKw6vAhc5bzC7aYOSBE/fOmJ72PGAQDpi1ufseVPAtaQb/M3pgz1Cy8fbGoASF08yI72LzkNhgnbSSyWXMTr19r7O3iyTC67V3ENdFNvZmnQXQdJ3p54eTHDs0Ev8nqxV/g="
62 | # # Ex. travis encrypt SONATYPE_PASSWORD=your_sonatype_password
63 | - secure: "FhyPYnFzModdYtBmvoI2H8RUig8MoJLRcEZXXYKaDvTKuUzMai5mEEZVt7hVNvIDEk/mqhziTL6bQ++sgZ7mzxRKcpxM3Z3+6fLFvibpV+IMt4C5hXiDZBgDrZGbM4aA2XWhXBHq37x/aOOQsIMHna7kv3IAnyw+KoAX0Hfj2X2914VxmUDMiobjwNIGMk9LUS+YeI8jYcssB4Dp+6QzpmuoVzxkd5paEOKE9GwP5BXRo2QaPu4BEK6op2dV4aG7E1GJenj+3bJfVGgl5/EGXI1KTLp0QZMRwYH3BiwVh5VVuHeNlv3R38y4bAoi3JuovqcsHBzkA9hic5IzrCkyTQIpq8k7upxPI+W9LDuPGjM24i6aWA8sO948UBMZ9Upvh8Cwxyt76tiOdujOXhbCzgXfnrnPkxDC6lmBDNH6raA6kIej80cA4Wrg/h/b7R5W9iRzAER2qzer2Vrn9Db/VSMwFy+UqC4ySznygZ6OzE0UBYF3oG2LXRHP0o96pjsiTdm+c3c5Rp1sSosrVnROCiurcppx4Z7sMTPBb4QVfzPnbcWwStiyAVp6oIs1hjBVJFs/uZS1R8YH3fGJWgOq5qyha+Q+T10M6vplJXAhknLuG7GL98S+LCERKBPuikT0dPaEQVBqNnGHmNl/W6YJ4oAggacx377kR8JDDCVcAz0="
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Annotation Error Decoder
2 | =========================
3 | [](https://gitter.im/OpenFeign/feign?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 | [](https://travis-ci.org/OpenFeign/feign-annotation-error-decoder)
5 | [ ](https://bintray.com/openfeign/maven/feign-annotation-error-decoder/_latestVersion)
6 | [](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign/feign-annotation-error-decoder)
7 |
8 | This module allows to annotate Feign's interfaces with annotations to generate Exceptions based on error codes
9 |
10 | To use AnnotationErrorDecoder with Feign, add the Annotation Error Decoder module to your classpath. Then, configure
11 | Feign to use the AnnotationErrorDecoder:
12 |
13 | ```java
14 | GitHub github = Feign.builder()
15 | .errorDecoder(
16 | AnnotationErrorDecoder.builderFor(GitHub.class).build()
17 | )
18 | .target(GitHub.class, "https://api.github.com");
19 | ```
20 |
21 | ## Leveraging the annotations and priority order
22 | For annotation decoding to work, the class must be annotated with `@ErrorHandling` tags.
23 | The tags are valid in both the class level as well as method level. They will be treated from 'most specific' to
24 | 'least specific' in the following order:
25 | * A code specific exception defined on the method
26 | * A code specific exception defined on the class
27 | * The default exception of the method
28 | * The default exception of the class
29 |
30 | ```java
31 | @ErrorHandling(codeSpecific =
32 | {
33 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class),
34 | @ErrorCodes( codes = {403}, generate = ForbiddenException.class),
35 | @ErrorCodes( codes = {404}, generate = UnknownItemException.class),
36 | },
37 | defaultException = ClassLevelDefaultException.class
38 | )
39 | interface GitHub {
40 |
41 | @ErrorHandling(codeSpecific =
42 | {
43 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class),
44 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class),
45 | },
46 | defaultException = FailedToGetContributorsException.class
47 | )
48 | @RequestLine("GET /repos/{owner}/{repo}/contributors")
49 | List contributors(@Param("owner") String owner, @Param("repo") String repo);
50 | }
51 | ```
52 | In the above example, error responses to 'contributors' would hence be mapped as follows by status codes:
53 |
54 | | Code | Exception | Reason |
55 | | ----------- | -------------------------------- | --------------------- |
56 | | 401 | `UnAuthorizedException` | from Class definition |
57 | | 403 | `ForbiddenException` | from Class definition |
58 | | 404 | `NonExistenRepoException` | from Method definition, note that the class generic exception won't be thrown here |
59 | | 502,503,504 | `RetryAfterCertainTimeException` | from method definition. Note that you can have multiple error codes generate the same type of exception |
60 | | Any Other | `FailedToGetContributorsException` | from Method default |
61 |
62 | For a class level default exception to be thrown, the method must not have a `defaultException` defined, nor must the error code
63 | be mapped at either the method or class level.
64 |
65 | If the return code cannot be mapped to any code and no default exceptions have been configured, then the decoder will
66 | drop to a default decoder (by default, the standard one provided by feign). You can change the default drop-into decoder
67 | as follows:
68 |
69 | ```java
70 | GitHub github = Feign.builder()
71 | .errorDecoder(
72 | AnnotationErrorDecoder.builderFor(GitHub.class)
73 | .withDefaultDecoder(new MyOtherErrorDecoder())
74 | .build()
75 | )
76 | .target(GitHub.class, "https://api.github.com");
77 | ```
78 |
79 |
80 | ## Complex Exceptions
81 |
82 | Any exception can be used if they have a default constructor:
83 |
84 | ```java
85 | class DefaultConstructorException extends Exception {}
86 | ```
87 |
88 | However, if you want to have parameters (such as the feign.Request object or response body or response headers), you have to annotate its
89 | constructor appropriately (the body annotation is optional, provided there aren't paramters which will clash)
90 |
91 | All the following examples are valid exceptions:
92 | ```java
93 | class JustBody extends Exception {
94 |
95 | @FeignExceptionConstructor
96 | public JustBody(String body) {
97 |
98 | }
99 | }
100 | class JustRequest extends Exception {
101 |
102 | @FeignExceptionConstructor
103 | public JustRequest(Request request) {
104 |
105 | }
106 | }
107 | class RequestAndResponseBody extends Exception {
108 |
109 | @FeignExceptionConstructor
110 | public RequestAndResponseBody(Request request, String body) {
111 |
112 | }
113 | }
114 | //Headers must be of type Map>
115 | class BodyAndHeaders extends Exception {
116 |
117 | @FeignExceptionConstructor
118 | public BodyAndHeaders(@ResponseBody String body, @ResponseHeaders Map> headers) {
119 |
120 | }
121 | }
122 | class RequestAndResponseBodyAndHeaders extends Exception {
123 |
124 | @FeignExceptionConstructor
125 | public RequestAndResponseBodyAndHeaders(Request request, @ResponseBody String body, @ResponseHeaders Map> headers) {
126 |
127 | }
128 | }
129 | class JustHeaders extends Exception {
130 |
131 | @FeignExceptionConstructor
132 | public JustHeaders(@ResponseHeaders Map> headers) {
133 |
134 | }
135 | }
136 | ```
137 |
138 | If you want to have the body decoded, you'll need to pass a decoder at construction time (just as for normal responses):
139 |
140 | ```java
141 | GitHub github = Feign.builder()
142 | .errorDecoder(
143 | AnnotationErrorDecoder.builderFor(GitHub.class)
144 | .withResponseBodyDecoder(new JacksonDecoder())
145 | .build()
146 | )
147 | .target(GitHub.class, "https://api.github.com");
148 | ```
149 |
150 | This will enable you to create exceptions where the body is a complex pojo:
151 |
152 | ```java
153 | class ComplexPojoException extends Exception {
154 |
155 | @FeignExceptionConstructor
156 | public ComplexPojoException(GithubExceptionResponse body) {
157 | if (body != null) {
158 | // extract data
159 | } else {
160 | // fallback code
161 | }
162 | }
163 | }
164 | //The pojo can then be anything you'd like provided the decoder can manage it
165 | class GithubExceptionResponse {
166 | public String message;
167 | public int githubCode;
168 | public List urlsForHelp;
169 | }
170 | ```
171 |
172 | It's worth noting that at setup/startup time, the generators are checked with a null value of the body.
173 | If you don't do the null-checker, you'll get an NPE and startup will fail.
174 |
175 |
176 | ## Inheriting from other interface definitions
177 | You can create a client interface that inherits from a different one. However, there are some limitations that
178 | you should be aware of (for most cases, these shouldn't be an issue):
179 | * The inheritance is not natural java inheritance of annotations - as these don't work on interfaces
180 | * Instead, the error looks at the class and if it finds the `@ErrorHandling` annotation, it uses that one.
181 | * If not, it will look at *all* the interfaces the main interface `extends` - but it does so in the order the
182 | java API gives it - so order is not guaranteed.
183 | * If it finds the annotation in one of those parents, it uses that definition, without looking at any other
184 | * That means that if more than one interface was extended which contained the `@ErrorHandling` annotation, we can't
185 | really guarantee which one of the parents will be selected and you should really do handling at the child interface
186 | * so far, the java API seems to return in order of definition after the `extends`, but it's a really bad practice
187 | if you have to depend on that... so our suggestion: don't.
188 |
189 | That means that as long as you only ever extend from a base interface (where you may decide that all 404's are "NotFoundException", for example)
190 | then you should be ok. But if you get complex in polymorphism, all bets are off - so don't go crazy!
191 |
192 | Example:
193 | In the following code:
194 | * The base `FeignClientBase` interface defines a default set of exceptions at class level
195 | * the `GitHub1` and `GitHub2` interfaces will inherit the class-level error handling, which means that
196 | any 401/403/404 will be handled correctly (provided the method doesn't specify a more specific exception)
197 | * the `GitHub3` interface however, by defining its own error handling, will handle all 401's, but not the
198 | 403/404's since there's no merging/etc (not really in the plan to implement either...)
199 | ```java
200 |
201 | @ErrorHandling(codeSpecific =
202 | {
203 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class),
204 | @ErrorCodes( codes = {403}, generate = ForbiddenException.class),
205 | @ErrorCodes( codes = {404}, generate = UnknownItemException.class),
206 | },
207 | defaultException = ClassLevelDefaultException.class
208 | )
209 | interface FeignClientBase {}
210 |
211 | interface GitHub1 extends FeignClientBase {
212 |
213 | @ErrorHandling(codeSpecific =
214 | {
215 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class),
216 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class),
217 | },
218 | defaultException = FailedToGetContributorsException.class
219 | )
220 | @RequestLine("GET /repos/{owner}/{repo}/contributors")
221 | List contributors(@Param("owner") String owner, @Param("repo") String repo);
222 | }
223 |
224 | interface GitHub2 extends FeignClientBase {
225 |
226 | @ErrorHandling(codeSpecific =
227 | {
228 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class),
229 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class),
230 | },
231 | defaultException = FailedToGetContributorsException.class
232 | )
233 | @RequestLine("GET /repos/{owner}/{repo}/contributors")
234 | List contributors(@Param("owner") String owner, @Param("repo") String repo);
235 | }
236 |
237 | @ErrorHandling(codeSpecific =
238 | {
239 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class)
240 | },
241 | defaultException = ClassLevelDefaultException.class
242 | )
243 | interface GitHub3 extends FeignClientBase {
244 |
245 | @ErrorHandling(codeSpecific =
246 | {
247 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class),
248 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class),
249 | },
250 | defaultException = FailedToGetContributorsException.class
251 | )
252 | @RequestLine("GET /repos/{owner}/{repo}/contributors")
253 | List contributors(@Param("owner") String owner, @Param("repo") String repo);
254 | }
255 | ```
--------------------------------------------------------------------------------
/RELEASE.md:
--------------------------------------------------------------------------------
1 | # Feign Annotation Error Decoder Release Process
2 |
3 | This repo uses [semantic versions](http://semver.org/). Please keep this in mind when choosing version numbers.
4 |
5 | 1. **Alert others you are releasing**
6 |
7 | There should be no commits made to master while the release is in progress (about 10 minutes). Before you start
8 | a release, alert others on [gitter](https://gitter.im/OpenFeign/feign) so that they don't accidentally merge
9 | anything. If they do, and the build fails because of that, you'll have to recreate the release tag described below.
10 |
11 | 1. **Push a git tag**
12 |
13 | The tag should be of the format `release-N.M.L`, for example `release-8.18.0`.
14 |
15 | You can do this either from the command line or via the github UI by creating a release.
16 |
17 | 1. **Wait for Travis CI**
18 |
19 | This part is controlled by [`travis/publish.sh`](travis/publish.sh). It creates a couple commits, bumps the version,
20 | publishes artifacts, syncs to Maven Central.
21 |
22 | ## Credentials
23 |
24 | Credentials of various kind are needed for the release process to work. If you notice something
25 | failing due to unauthorized, re-encrypt them using instructions at the bottom of the `.travis.yml`
26 |
27 | Ex You'll see comments like this:
28 | ```yaml
29 | env:
30 | global:
31 | # Ex. travis encrypt BINTRAY_USER=your_github_account
32 | - secure: "VeTO...
33 | ```
34 |
35 | To re-encrypt, you literally run the commands with relevant values and replace the "secure" key with the output:
36 |
37 | ```bash
38 | $ travis encrypt BINTRAY_USER=adrianmole
39 | Please add the following to your .travis.yml file:
40 |
41 | secure: "mQnECL+dXc5l9wCYl/wUz+AaYFGt/1G31NAZcTLf2RbhKo8mUenc4hZNjHCEv+4ZvfYLd/NoTNMhTCxmtBMz1q4CahPKLWCZLoRD1ExeXwRymJPIhxZUPzx9yHPHc5dmgrSYOCJLJKJmHiOl9/bJi123456="
42 | ```
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | #
58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look
59 | # for the new JDKs provided by Oracle.
60 | #
61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
62 | #
63 | # Apple JDKs
64 | #
65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
66 | fi
67 |
68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
69 | #
70 | # Apple JDKs
71 | #
72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
73 | fi
74 |
75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
76 | #
77 | # Oracle JDKs
78 | #
79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
80 | fi
81 |
82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
83 | #
84 | # Apple JDKs
85 | #
86 | export JAVA_HOME=`/usr/libexec/java_home`
87 | fi
88 | ;;
89 | esac
90 |
91 | if [ -z "$JAVA_HOME" ] ; then
92 | if [ -r /etc/gentoo-release ] ; then
93 | JAVA_HOME=`java-config --jre-home`
94 | fi
95 | fi
96 |
97 | if [ -z "$M2_HOME" ] ; then
98 | ## resolve links - $0 may be a link to maven's home
99 | PRG="$0"
100 |
101 | # need this for relative symlinks
102 | while [ -h "$PRG" ] ; do
103 | ls=`ls -ld "$PRG"`
104 | link=`expr "$ls" : '.*-> \(.*\)$'`
105 | if expr "$link" : '/.*' > /dev/null; then
106 | PRG="$link"
107 | else
108 | PRG="`dirname "$PRG"`/$link"
109 | fi
110 | done
111 |
112 | saveddir=`pwd`
113 |
114 | M2_HOME=`dirname "$PRG"`/..
115 |
116 | # make it fully qualified
117 | M2_HOME=`cd "$M2_HOME" && pwd`
118 |
119 | cd "$saveddir"
120 | # echo Using m2 at $M2_HOME
121 | fi
122 |
123 | # For Cygwin, ensure paths are in UNIX format before anything is touched
124 | if $cygwin ; then
125 | [ -n "$M2_HOME" ] &&
126 | M2_HOME=`cygpath --unix "$M2_HOME"`
127 | [ -n "$JAVA_HOME" ] &&
128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129 | [ -n "$CLASSPATH" ] &&
130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
131 | fi
132 |
133 | # For Migwn, ensure paths are in UNIX format before anything is touched
134 | if $mingw ; then
135 | [ -n "$M2_HOME" ] &&
136 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
137 | [ -n "$JAVA_HOME" ] &&
138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
139 | # TODO classpath?
140 | fi
141 |
142 | if [ -z "$JAVA_HOME" ]; then
143 | javaExecutable="`which javac`"
144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
145 | # readlink(1) is not available as standard on Solaris 10.
146 | readLink=`which readlink`
147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
148 | if $darwin ; then
149 | javaHome="`dirname \"$javaExecutable\"`"
150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
151 | else
152 | javaExecutable="`readlink -f \"$javaExecutable\"`"
153 | fi
154 | javaHome="`dirname \"$javaExecutable\"`"
155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
156 | JAVA_HOME="$javaHome"
157 | export JAVA_HOME
158 | fi
159 | fi
160 | fi
161 |
162 | if [ -z "$JAVACMD" ] ; then
163 | if [ -n "$JAVA_HOME" ] ; then
164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
165 | # IBM's JDK on AIX uses strange locations for the executables
166 | JAVACMD="$JAVA_HOME/jre/sh/java"
167 | else
168 | JAVACMD="$JAVA_HOME/bin/java"
169 | fi
170 | else
171 | JAVACMD="`which java`"
172 | fi
173 | fi
174 |
175 | if [ ! -x "$JAVACMD" ] ; then
176 | echo "Error: JAVA_HOME is not defined correctly." >&2
177 | echo " We cannot execute $JAVACMD" >&2
178 | exit 1
179 | fi
180 |
181 | if [ -z "$JAVA_HOME" ] ; then
182 | echo "Warning: JAVA_HOME environment variable is not set."
183 | fi
184 |
185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
186 |
187 | # traverses directory structure from process work directory to filesystem root
188 | # first directory with .mvn subdirectory is considered project base directory
189 | find_maven_basedir() {
190 | local basedir=$(pwd)
191 | local wdir=$(pwd)
192 | while [ "$wdir" != '/' ] ; do
193 | if [ -d "$wdir"/.mvn ] ; then
194 | basedir=$wdir
195 | break
196 | fi
197 | wdir=$(cd "$wdir/.."; pwd)
198 | done
199 | echo "${basedir}"
200 | }
201 |
202 | # concatenates all lines of a file
203 | concat_lines() {
204 | if [ -f "$1" ]; then
205 | echo "$(tr -s '\n' ' ' < "$1")"
206 | fi
207 | }
208 |
209 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
210 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
211 |
212 | # For Cygwin, switch paths to Windows format before running java
213 | if $cygwin; then
214 | [ -n "$M2_HOME" ] &&
215 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
216 | [ -n "$JAVA_HOME" ] &&
217 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
218 | [ -n "$CLASSPATH" ] &&
219 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
220 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
221 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
222 | fi
223 |
224 | # Provide a "standardized" way to retrieve the CLI args that will
225 | # work with both Windows and non-Windows executions.
226 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
227 | export MAVEN_CMD_LINE_ARGS
228 |
229 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
230 |
231 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@
232 | exec "$JAVACMD" \
233 | $MAVEN_OPTS \
234 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
235 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
236 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
237 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 4.0.0
19 |
20 |
21 | io.github.openfeign
22 | parent
23 | 10.7.0
24 |
25 |
26 | feign-annotation-error-decoder
27 | 1.3.1-SNAPSHOT
28 | Feign Annotation Error Decoder
29 | Feign Annotation Error Decoder
30 | https://github.com/OpenFeign/feign-annotation-error-decoder
31 | 2017
32 |
33 |
34 | OpenFeign
35 | https://github.com/openfeign
36 |
37 |
38 |
39 |
40 | The Apache Software License, Version 2.0
41 | http://www.apache.org/licenses/LICENSE-2.0.txt
42 | repo
43 |
44 |
45 |
46 |
47 | https://github.com/OpenFeign/feign-annotation-error-decoder
48 | scm:git:https://github.com/OpenFeign/feign-annotation-error-decoder.git
49 | scm:git:https://github.com/OpenFeign/feign-annotation-error-decoder.git
50 | HEAD
51 |
52 |
53 |
54 |
55 | saintf
56 | Fernando Saint-Jean
57 | fsaintjean@gmail.com
58 |
59 |
60 |
61 |
62 |
63 | bintray
64 | https://api.bintray.com/maven/openfeign/maven/feign-annotation-error-decoder/;publish=1
65 |
66 |
67 | jfrog-snapshots
68 | http://oss.jfrog.org/artifactory/oss-snapshot-local
69 |
70 |
71 |
72 |
73 | Github
74 | https://github.com/openfeign/feign-annotation-error-decoder/issues
75 |
76 |
77 |
78 |
79 | ${project.groupId}
80 | feign-core
81 | ${project.parent.version}
82 | provided
83 |
84 |
85 |
86 | ${project.groupId}
87 | feign-core
88 | ${project.parent.version}
89 | test-jar
90 | test
91 |
92 |
93 |
94 | com.squareup.okhttp3
95 | mockwebserver
96 | test
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | maven-jar-plugin
105 | ${maven-jar-plugin.version}
106 |
107 |
108 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
109 |
110 |
111 |
112 |
113 | maven-compiler-plugin
114 |
115 |
116 |
117 | default-compile
118 | compile
119 |
120 | compile
121 |
122 |
123 | ${main.java.version}
124 | ${main.java.version}
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | org.codehaus.mojo
135 | animal-sniffer-maven-plugin
136 | ${animal-sniffer-maven-plugin.version}
137 |
138 |
139 | org.codehaus.mojo.signature
140 | ${main.signature.artifact}
141 | 1.0
142 |
143 |
144 |
145 |
146 |
147 | check
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 | maven-install-plugin
156 | ${maven-install-plugin.version}
157 |
158 | true
159 |
160 |
161 |
162 |
163 | maven-release-plugin
164 | ${maven-release-plugin.version}
165 |
166 | false
167 | release
168 | true
169 | @{project.version}
170 |
171 |
172 |
173 |
174 | io.zipkin.centralsync-maven-plugin
175 | centralsync-maven-plugin
176 | ${centralsync-maven-plugin.version}
177 |
178 | openfeign
179 | maven
180 | feign-annotation-error-decoder
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | release
189 |
190 |
191 |
192 |
193 | maven-source-plugin
194 | ${maven-source-plugin.version}
195 |
196 |
197 | attach-sources
198 |
199 | jar
200 |
201 |
202 |
203 |
204 |
205 |
206 | maven-javadoc-plugin
207 | ${maven-javadoc-plugin.version}
208 |
209 | false
210 |
211 |
212 |
213 | attach-javadocs
214 |
215 | jar
216 |
217 | package
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
--------------------------------------------------------------------------------
/src/config/bom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 4.0.0
19 |
20 | ${model.groupId}
21 | ${model.artifactId}
22 | ${model.version}
23 | ${model.name}
24 | pom
25 | Bill of material
26 | #if ($model.url)
27 |
28 | ${model.url}#end
29 | #if ($model.licenses && !$model.licenses.isEmpty())
30 |
31 | #foreach($l in $model.licenses)
32 |
33 |
34 | ${l.name}
35 | ${l.url}
36 | ${l.distribution}
37 | #end
38 |
39 |
40 | #end
41 |
42 | #if ($model.developers && !$model.developers.isEmpty())
43 | #foreach($d in $model.developers)
44 |
45 |
46 | ${d.id}
47 | ${d.name}#if($d.email)
48 |
49 | ${d.email}#end#if($d.url)
50 |
51 | ${d.url}#end#if($d.organization)
52 |
53 | ${d.organization}#end#if($d.organizationUrl)
54 |
55 | ${d.organizationUrl}#end
56 |
57 | #end
58 |
59 |
60 | #end
61 |
62 |
63 | #foreach($d in $model.dependencyManagement.dependencies)
64 |
65 |
66 | ${d.groupId}
67 | ${d.artifactId}
68 | ${d.version}#if( $d.scope && $!d.scope != '' )
69 |
70 | ${d.scope}#end#if( $d.type && $!d.type != '' && $!d.type != 'jar' && $!d.type != 'bundle')
71 |
72 | ${d.type}#end#if( $d.classifier && $!d.classifier != '' )
73 |
74 | ${d.classifier}#end#if( $d.exclusions && $d.exclusions.size() > 0 )
75 |
76 | #foreach( $e in $d.exclusions )
77 |
78 |
79 | ${e.groupId}
80 | ${e.artifactId}
81 | #end
82 |
83 | #end
84 |
85 | #end
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/src/config/eclipse-java-style.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
--------------------------------------------------------------------------------
/src/config/pomSortOrder.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
--------------------------------------------------------------------------------
/src/etc/header.txt:
--------------------------------------------------------------------------------
1 | Copyright ${license.git.copyrightYears} The Feign Authors
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4 | in compliance with the License. You may obtain a copy of the License at
5 |
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software distributed under the License
9 | is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10 | or implied. See the License for the specific language governing permissions and limitations under
11 | the License.
12 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/AnnotationErrorDecoder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import feign.Response;
17 | import feign.codec.Decoder;
18 | import feign.codec.ErrorDecoder;
19 | import java.lang.reflect.Method;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 | import java.util.Optional;
23 | import static feign.Feign.configKey;
24 |
25 | public class AnnotationErrorDecoder implements ErrorDecoder {
26 |
27 | private final Map errorHandlerMap;
28 | private final ErrorDecoder defaultDecoder;
29 |
30 |
31 | AnnotationErrorDecoder(Map errorHandlerMap,
32 | ErrorDecoder defaultDecoder) {
33 | this.errorHandlerMap = errorHandlerMap;
34 | this.defaultDecoder = defaultDecoder;
35 | }
36 |
37 | @Override
38 | public Exception decode(String methodKey, Response response) {
39 | if (errorHandlerMap.containsKey(methodKey)) {
40 | return errorHandlerMap.get(methodKey).decode(response);
41 | }
42 | return defaultDecoder.decode(methodKey, response);
43 | }
44 |
45 |
46 | public static AnnotationErrorDecoder.Builder builderFor(Class> apiType) {
47 | return new Builder(apiType);
48 | }
49 |
50 | public static class Builder {
51 | private final Class> apiType;
52 | private ErrorDecoder defaultDecoder = new ErrorDecoder.Default();
53 | private Decoder responseBodyDecoder = new Decoder.Default();
54 |
55 |
56 | public Builder(Class> apiType) {
57 | this.apiType = apiType;
58 | }
59 |
60 | public Builder withDefaultDecoder(ErrorDecoder defaultDecoder) {
61 | this.defaultDecoder = defaultDecoder;
62 | return this;
63 | }
64 |
65 | public Builder withResponseBodyDecoder(Decoder responseBodyDecoder) {
66 | this.responseBodyDecoder = responseBodyDecoder;
67 | return this;
68 | }
69 |
70 | public AnnotationErrorDecoder build() {
71 | Map errorHandlerMap = generateErrorHandlerMapFromApi(apiType);
72 | return new AnnotationErrorDecoder(errorHandlerMap, defaultDecoder);
73 | }
74 |
75 | Map generateErrorHandlerMapFromApi(Class> apiType) {
76 |
77 | ExceptionGenerator classLevelDefault = new ExceptionGenerator.Builder()
78 | .withResponseBodyDecoder(responseBodyDecoder)
79 | .withExceptionType(ErrorHandling.NO_DEFAULT.class)
80 | .build();
81 | Map classLevelStatusCodeDefinitions =
82 | new HashMap();
83 |
84 | Optional classLevelErrorHandling =
85 | readErrorHandlingIncludingInherited(apiType);
86 | if (classLevelErrorHandling.isPresent()) {
87 | ErrorHandlingDefinition classErrorHandlingDefinition =
88 | readAnnotation(classLevelErrorHandling.get(), responseBodyDecoder);
89 | classLevelDefault = classErrorHandlingDefinition.defaultThrow;
90 | classLevelStatusCodeDefinitions = classErrorHandlingDefinition.statusCodesMap;
91 | }
92 |
93 | Map methodErrorHandlerMap =
94 | new HashMap();
95 | for (Method method : apiType.getMethods()) {
96 | if (method.isAnnotationPresent(ErrorHandling.class)) {
97 | ErrorHandlingDefinition methodErrorHandling =
98 | readAnnotation(method.getAnnotation(ErrorHandling.class), responseBodyDecoder);
99 | ExceptionGenerator methodDefault = methodErrorHandling.defaultThrow;
100 | if (methodDefault.getExceptionType().equals(ErrorHandling.NO_DEFAULT.class)) {
101 | methodDefault = classLevelDefault;
102 | }
103 |
104 | MethodErrorHandler methodErrorHandler =
105 | new MethodErrorHandler(methodErrorHandling.statusCodesMap,
106 | classLevelStatusCodeDefinitions, methodDefault);
107 |
108 | methodErrorHandlerMap.put(configKey(apiType, method), methodErrorHandler);
109 | }
110 | }
111 |
112 | return methodErrorHandlerMap;
113 | }
114 |
115 | Optional readErrorHandlingIncludingInherited(Class> apiType) {
116 | if (apiType.isAnnotationPresent(ErrorHandling.class)) {
117 | return Optional.of(apiType.getAnnotation(ErrorHandling.class));
118 | }
119 | for (Class> parentInterface : apiType.getInterfaces()) {
120 | Optional errorHandling =
121 | readErrorHandlingIncludingInherited(parentInterface);
122 | if (errorHandling.isPresent()) {
123 | return errorHandling;
124 | }
125 | }
126 | // Finally, if there's a superclass that isn't Object check if the superclass has anything
127 | if (!apiType.isInterface() && !apiType.getSuperclass().equals(Object.class)) {
128 | return readErrorHandlingIncludingInherited(apiType.getSuperclass());
129 | }
130 | return Optional.empty();
131 | }
132 |
133 | static ErrorHandlingDefinition readAnnotation(ErrorHandling errorHandling,
134 | Decoder responseBodyDecoder) {
135 | ExceptionGenerator defaultException = new ExceptionGenerator.Builder()
136 | .withResponseBodyDecoder(responseBodyDecoder)
137 | .withExceptionType(errorHandling.defaultException())
138 | .build();
139 | Map statusCodesDefinition =
140 | new HashMap();
141 |
142 | for (ErrorCodes statusCodeDefinition : errorHandling.codeSpecific()) {
143 | for (int statusCode : statusCodeDefinition.codes()) {
144 | if (statusCodesDefinition.containsKey(statusCode)) {
145 | throw new IllegalStateException(
146 | "Status Code [" + statusCode + "] " +
147 | "has already been declared to throw ["
148 | + statusCodesDefinition.get(statusCode).getExceptionType().getName() + "] " +
149 | "and [" + statusCodeDefinition.generate() + "] - dupe definition");
150 | }
151 | statusCodesDefinition.put(statusCode,
152 | new ExceptionGenerator.Builder()
153 | .withResponseBodyDecoder(responseBodyDecoder)
154 | .withExceptionType(statusCodeDefinition.generate())
155 | .build());
156 | }
157 | }
158 |
159 | return new ErrorHandlingDefinition(defaultException, statusCodesDefinition);
160 | }
161 |
162 | private static class ErrorHandlingDefinition {
163 | private final ExceptionGenerator defaultThrow;
164 | private final Map statusCodesMap;
165 |
166 |
167 | private ErrorHandlingDefinition(ExceptionGenerator defaultThrow,
168 | Map statusCodesMap) {
169 | this.defaultThrow = defaultThrow;
170 | this.statusCodesMap = statusCodesMap;
171 | }
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/ErrorCodes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | public @interface ErrorCodes {
17 | int[] codes();
18 |
19 | Class extends Exception> generate();
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/ErrorHandling.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import feign.Response;
17 | import java.lang.annotation.ElementType;
18 | import java.lang.annotation.Inherited;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | @Inherited
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target({ElementType.TYPE, ElementType.METHOD})
26 | public @interface ErrorHandling {
27 | ErrorCodes[] codeSpecific() default {};
28 |
29 | Class extends Exception> defaultException() default NO_DEFAULT.class;
30 |
31 | final class NO_DEFAULT extends Exception {
32 | @FeignExceptionConstructor
33 | public NO_DEFAULT(@ResponseBody Response response) {
34 | super("Endpoint responded with " + response.status() + ", reason: " + response.reason());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/ExceptionGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import feign.Request;
17 | import feign.Response;
18 | import feign.Types;
19 | import feign.codec.DecodeException;
20 | import feign.codec.Decoder;
21 | import java.io.IOException;
22 | import java.lang.annotation.Annotation;
23 | import java.lang.reflect.Constructor;
24 | import java.lang.reflect.InvocationTargetException;
25 | import java.lang.reflect.Type;
26 | import java.util.Arrays;
27 | import java.util.Collection;
28 | import java.util.HashMap;
29 | import java.util.Map;
30 | import static feign.Util.checkState;
31 |
32 | class ExceptionGenerator {
33 |
34 | private static final Response TEST_RESPONSE;
35 |
36 | static {
37 | Map> testHeaders = new HashMap>();
38 | testHeaders.put("TestHeader", Arrays.asList("header-value"));
39 |
40 | TEST_RESPONSE = Response.builder()
41 | .status(500)
42 | .body((Response.Body) null)
43 | .headers(testHeaders)
44 | .request(Request.create(Request.HttpMethod.GET, "http://test", testHeaders,
45 | Request.Body.empty(), null))
46 | .build();
47 | }
48 |
49 | private final Integer bodyIndex;
50 | private final Integer requestIndex;
51 | private final Integer headerMapIndex;
52 | private final Integer numOfParams;
53 | private final Type bodyType;
54 | private final Class extends Exception> exceptionType;
55 | private final Decoder bodyDecoder;
56 |
57 | ExceptionGenerator(Integer bodyIndex, Integer requestIndex, Integer headerMapIndex,
58 | Integer numOfParams, Type bodyType,
59 | Class extends Exception> exceptionType, Decoder bodyDecoder) {
60 | this.bodyIndex = bodyIndex;
61 | this.requestIndex = requestIndex;
62 | this.headerMapIndex = headerMapIndex;
63 | this.numOfParams = numOfParams;
64 | this.bodyType = bodyType;
65 | this.exceptionType = exceptionType;
66 | this.bodyDecoder = bodyDecoder;
67 | }
68 |
69 |
70 | Exception createException(Response response) throws InvocationTargetException,
71 | NoSuchMethodException, InstantiationException, IllegalAccessException {
72 |
73 | Class>[] paramClasses = new Class[numOfParams];
74 | Object[] paramValues = new Object[numOfParams];
75 | if (bodyIndex >= 0) {
76 | paramClasses[bodyIndex] = Types.getRawType(bodyType);
77 | paramValues[bodyIndex] = resolveBody(response);
78 | }
79 | if (requestIndex >= 0) {
80 | paramClasses[requestIndex] = Request.class;
81 | paramValues[requestIndex] = response.request();
82 | }
83 | if (headerMapIndex >= 0) {
84 | paramValues[headerMapIndex] = response.headers();
85 | paramClasses[headerMapIndex] = Map.class;
86 | }
87 | return exceptionType.getConstructor(paramClasses)
88 | .newInstance(paramValues);
89 |
90 | }
91 |
92 | Class extends Exception> getExceptionType() {
93 | return exceptionType;
94 | }
95 |
96 | private Object resolveBody(Response response) {
97 | if (bodyType instanceof Class> && ((Class>) bodyType).isInstance(response)) {
98 | return response;
99 | }
100 | try {
101 | return bodyDecoder.decode(response, bodyType);
102 | } catch (IOException e) {
103 | // How do we log this?
104 | return null;
105 | } catch (DecodeException e) {
106 | // How do we log this?
107 | return null;
108 | }
109 | }
110 |
111 | static class Builder {
112 | private Class extends Exception> exceptionType;
113 | private Decoder responseBodyDecoder;
114 |
115 | public Builder withExceptionType(Class extends Exception> exceptionType) {
116 | this.exceptionType = exceptionType;
117 | return this;
118 | }
119 |
120 | public Builder withResponseBodyDecoder(Decoder bodyDecoder) {
121 | this.responseBodyDecoder = bodyDecoder;
122 | return this;
123 | }
124 |
125 | public ExceptionGenerator build() {
126 | Constructor extends Exception> constructor = getConstructor(exceptionType);
127 | Type[] parameterTypes = constructor.getGenericParameterTypes();
128 | Annotation[][] parametersAnnotations = constructor.getParameterAnnotations();
129 |
130 | Integer bodyIndex = -1;
131 | Integer requestIndex = -1;
132 | Integer headerMapIndex = -1;
133 | Integer numOfParams = parameterTypes.length;
134 | Type bodyType = null;
135 |
136 | for (int i = 0; i < parameterTypes.length; i++) {
137 | Annotation[] paramAnnotations = parametersAnnotations[i];
138 | boolean foundAnnotation = false;
139 | for (Annotation annotation : paramAnnotations) {
140 | if (annotation.annotationType().equals(ResponseHeaders.class)) {
141 | checkState(headerMapIndex == -1,
142 | "Cannot have two parameters tagged with @ResponseHeaders");
143 | checkState(Types.getRawType(parameterTypes[i]).equals(Map.class),
144 | "Response Header map must be of type Map, but was %s", parameterTypes[i]);
145 | headerMapIndex = i;
146 | foundAnnotation = true;
147 | break;
148 | }
149 | }
150 | if (!foundAnnotation) {
151 | if (parameterTypes[i].equals(Request.class)) {
152 | checkState(requestIndex == -1,
153 | "Cannot have two parameters either without annotations or with object of type feign.Request");
154 | requestIndex = i;
155 | } else {
156 | checkState(bodyIndex == -1,
157 | "Cannot have two parameters either without annotations or with @ResponseBody annotation");
158 | bodyIndex = i;
159 | bodyType = parameterTypes[i];
160 | }
161 | }
162 | }
163 |
164 | ExceptionGenerator generator = new ExceptionGenerator(
165 | bodyIndex,
166 | requestIndex,
167 | headerMapIndex,
168 | numOfParams,
169 | bodyType,
170 | exceptionType,
171 | responseBodyDecoder);
172 |
173 | validateGeneratorCanBeUsedToGenerateExceptions(generator);
174 | return generator;
175 | }
176 |
177 | private void validateGeneratorCanBeUsedToGenerateExceptions(ExceptionGenerator generator) {
178 | try {
179 | generator.createException(TEST_RESPONSE);
180 | } catch (Exception e) {
181 | throw new IllegalStateException(
182 | "Cannot generate exception - check constructor parameter types (are headers Map> or is something causing an exception on construction?)",
183 | e);
184 | }
185 | }
186 |
187 | private Constructor extends Exception> getConstructor(Class extends Exception> exceptionClass) {
188 | Constructor extends Exception> preferredConstructor = null;
189 | for (Constructor> constructor : exceptionClass.getConstructors()) {
190 |
191 | FeignExceptionConstructor exceptionConstructor =
192 | constructor.getAnnotation(FeignExceptionConstructor.class);
193 | if (exceptionConstructor == null) {
194 | continue;
195 | }
196 | Class>[] parameterTypes = constructor.getParameterTypes();
197 | if (parameterTypes.length == 0) {
198 | continue;
199 | }
200 | if (preferredConstructor == null) {
201 | preferredConstructor = (Constructor extends Exception>) constructor;
202 | } else {
203 | throw new IllegalStateException(
204 | "Too many constructors marked with @FeignExceptionConstructor");
205 | }
206 | }
207 |
208 | if (preferredConstructor == null) {
209 | try {
210 | return exceptionClass.getConstructor();
211 | } catch (NoSuchMethodException e) {
212 | throw new IllegalStateException(
213 | "Cannot find any suitable constructor in class [" + exceptionClass.getName()
214 | + "] - did you forget to mark one with @FeignExceptionConstructor or at least have a public default constructor?",
215 | e);
216 | }
217 | }
218 | return preferredConstructor;
219 | }
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/FeignExceptionConstructor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import java.lang.annotation.ElementType;
17 | import java.lang.annotation.Retention;
18 | import java.lang.annotation.RetentionPolicy;
19 | import java.lang.annotation.Target;
20 |
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Target({ElementType.CONSTRUCTOR})
23 | public @interface FeignExceptionConstructor {
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/MethodErrorHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import feign.Response;
17 | import java.lang.reflect.InvocationTargetException;
18 | import java.util.Map;
19 |
20 | class MethodErrorHandler {
21 |
22 | private final Map methodLevelExceptionsByCode;
23 | private final Map classLevelExceptionsByCode;
24 | private final ExceptionGenerator defaultException;
25 |
26 | MethodErrorHandler(Map methodLevelExceptionsByCode,
27 | Map classLevelExceptionsByCode,
28 | ExceptionGenerator defaultException) {
29 | this.methodLevelExceptionsByCode = methodLevelExceptionsByCode;
30 | this.classLevelExceptionsByCode = classLevelExceptionsByCode;
31 | this.defaultException = defaultException;
32 | }
33 |
34 |
35 | public Exception decode(Response response) {
36 | ExceptionGenerator constructorDefinition = getConstructorDefinition(response);
37 | return createException(constructorDefinition, response);
38 | }
39 |
40 | private ExceptionGenerator getConstructorDefinition(Response response) {
41 | if (methodLevelExceptionsByCode.containsKey(response.status())) {
42 | return methodLevelExceptionsByCode.get(response.status());
43 | }
44 | if (classLevelExceptionsByCode.containsKey(response.status())) {
45 | return classLevelExceptionsByCode.get(response.status());
46 | }
47 | return defaultException;
48 | }
49 |
50 | protected Exception createException(ExceptionGenerator constructorDefinition, Response response) {
51 | try {
52 | return constructorDefinition.createException(response);
53 | } catch (IllegalAccessException e) {
54 | throw new IllegalStateException("Cannot access constructor", e);
55 | } catch (InstantiationException e) {
56 | throw new IllegalStateException("Cannot instantiate exception with constructor", e);
57 | } catch (InvocationTargetException e) {
58 | throw new IllegalStateException("Cannot invoke constructor", e);
59 | } catch (NoSuchMethodException e) {
60 | throw new IllegalStateException("Constructor does not exist", e);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/ResponseBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import java.lang.annotation.ElementType;
17 | import java.lang.annotation.Retention;
18 | import java.lang.annotation.RetentionPolicy;
19 | import java.lang.annotation.Target;
20 |
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Target({ElementType.PARAMETER})
23 | public @interface ResponseBody {
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/feign/error/ResponseHeaders.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import java.lang.annotation.ElementType;
17 | import java.lang.annotation.Retention;
18 | import java.lang.annotation.RetentionPolicy;
19 | import java.lang.annotation.Target;
20 |
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Target({ElementType.PARAMETER})
23 | public @interface ResponseHeaders {
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/feign/error/AbstractAnnotationErrorDecoderTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import feign.Request;
17 | import feign.Response;
18 | import java.nio.charset.StandardCharsets;
19 | import java.util.Collection;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 | import static feign.Feign.configKey;
23 |
24 | public abstract class AbstractAnnotationErrorDecoderTest {
25 |
26 |
27 |
28 | public abstract Class interfaceAtTest();
29 |
30 | String feignConfigKey(String methodName) throws NoSuchMethodException {
31 | return configKey(interfaceAtTest(), interfaceAtTest().getMethod(methodName));
32 | }
33 |
34 | Response testResponse(int status) {
35 | return testResponse(status, "default Response body");
36 | }
37 |
38 | Response testResponse(int status, String body) {
39 | return testResponse(status, body, new HashMap>());
40 | }
41 |
42 | Response testResponse(int status, String body, Map> headers) {
43 | return Response.builder()
44 | .status(status)
45 | .body(body, StandardCharsets.UTF_8)
46 | .headers(headers)
47 | .request(Request.create(Request.HttpMethod.GET, "http://test", headers,
48 | Request.Body.empty(), null))
49 | .build();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/feign/error/AnnotationErrorDecoderClassInheritanceTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017-2019 The Feign Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package feign.error;
15 |
16 | import static org.assertj.core.api.Assertions.assertThat;
17 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1NotFoundException;
18 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException;
19 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method2NotFoundException;
20 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException;
21 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelNotFoundException;
22 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1DefaultException;
23 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method3DefaultException;
24 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelDefaultException;
25 | import java.util.Arrays;
26 | import org.junit.Test;
27 | import org.junit.runner.RunWith;
28 | import org.junit.runners.Parameterized;
29 | import org.junit.runners.Parameterized.Parameter;
30 | import org.junit.runners.Parameterized.Parameters;
31 |
32 | @RunWith(Parameterized.class)
33 | public class AnnotationErrorDecoderClassInheritanceTest extends
34 | AbstractAnnotationErrorDecoderTest {
35 |
36 | @Override
37 | public Class interfaceAtTest() {
38 | return GrandChild.class;
39 | }
40 |
41 | @Parameters(
42 | name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
43 | public static Iterable