29
29
import com .netflix .spinnaker .kork .core .RetrySupport ;
30
30
import com .netflix .spinnaker .kork .exceptions .SpinnakerException ;
31
31
import com .netflix .spinnaker .kork .exceptions .SystemException ;
32
+ import com .netflix .spinnaker .kork .retrofit .exceptions .SpinnakerHttpException ;
33
+ import com .netflix .spinnaker .kork .retrofit .exceptions .SpinnakerServerException ;
32
34
import com .netflix .spinnaker .security .AuthenticatedRequest ;
33
35
import com .netflix .spinnaker .security .User ;
34
36
import java .time .Duration ;
47
49
import org .springframework .stereotype .Component ;
48
50
import org .springframework .util .CollectionUtils ;
49
51
import org .springframework .util .StringUtils ;
50
- import retrofit .RetrofitError ;
51
52
52
53
@ Log4j2
53
54
@ Component
@@ -83,7 +84,7 @@ public void login(final String userId) {
83
84
permissionEvaluator .invalidatePermission (userId );
84
85
return null ;
85
86
});
86
- } catch (RetrofitError e ) {
87
+ } catch (SpinnakerServerException e ) {
87
88
throw UpstreamBadRequest .classifyError (e );
88
89
}
89
90
}
@@ -98,7 +99,7 @@ public void loginWithRoles(final String userId, final Collection<String> roles)
98
99
permissionEvaluator .invalidatePermission (userId );
99
100
return null ;
100
101
});
101
- } catch (RetrofitError e ) {
102
+ } catch (SpinnakerServerException e ) {
102
103
throw UpstreamBadRequest .classifyError (e );
103
104
}
104
105
}
@@ -109,7 +110,7 @@ public void logout(String userId) {
109
110
try {
110
111
getFiatServiceForLogin ().logoutUser (userId );
111
112
permissionEvaluator .invalidatePermission (userId );
112
- } catch (RetrofitError e ) {
113
+ } catch (SpinnakerServerException e ) {
113
114
throw UpstreamBadRequest .classifyError (e );
114
115
}
115
116
}
@@ -119,7 +120,7 @@ public void sync() {
119
120
if (fiatStatus .isEnabled ()) {
120
121
try {
121
122
getFiatServiceForLogin ().sync (List .of ());
122
- } catch (RetrofitError e ) {
123
+ } catch (SpinnakerServerException e ) {
123
124
throw UpstreamBadRequest .classifyError (e );
124
125
}
125
126
}
@@ -133,22 +134,22 @@ public Set<Role.View> getRoles(String userId) {
133
134
var permission = permissionEvaluator .getPermission (userId );
134
135
var roles = permission != null ? permission .getRoles () : null ;
135
136
return roles != null ? roles : Set .of ();
136
- } catch (RetrofitError e ) {
137
+ } catch (SpinnakerServerException e ) {
137
138
throw UpstreamBadRequest .classifyError (e );
138
139
}
139
140
}
140
141
141
142
List <UserPermission .View > lookupServiceAccounts (String userId ) {
142
143
try {
143
144
return extendedFiatService .getUserServiceAccounts (userId );
144
- } catch (RetrofitError re ) {
145
- var response = re .getResponse ();
146
- if (response != null && response .getStatus () == HttpStatus .NOT_FOUND .value ()) {
145
+ } catch (SpinnakerHttpException e ) {
146
+ if (e .getResponseCode () == 404 ) {
147
147
return List .of ();
148
148
}
149
- boolean shouldRetry =
150
- response == null || HttpStatus .valueOf (response .getStatus ()).is5xxServerError ();
151
- throw new SystemException ("getUserServiceAccounts failed" , re ).setRetryable (shouldRetry );
149
+ boolean shouldRetry = HttpStatus .valueOf (e .getResponseCode ()).is5xxServerError ();
150
+ throw new SystemException ("getUserServiceAccounts failed" , e ).setRetryable (shouldRetry );
151
+ } catch (SpinnakerServerException e ) {
152
+ throw new SystemException ("getUserServiceAccounts failed" , e ).setRetryable (e .getRetryable ());
152
153
}
153
154
}
154
155
@@ -217,8 +218,8 @@ public List<String> getServiceAccounts(@SpinnakerUser User user) {
217
218
return permission .getServiceAccounts ().stream ()
218
219
.map (ServiceAccount .View ::getName )
219
220
.collect (Collectors .toList ());
220
- } catch (RetrofitError re ) {
221
- throw UpstreamBadRequest .classifyError (re );
221
+ } catch (SpinnakerServerException e ) {
222
+ throw UpstreamBadRequest .classifyError (e );
222
223
}
223
224
}
224
225
0 commit comments