@@ -49,27 +49,29 @@ public KafkaRequest getKafkaById(String kafkaId, String accessToken)
49
49
try {
50
50
return createClient (accessToken ).getKafkaById (kafkaId );
51
51
} catch (ApiException e ) {
52
+ String message = getStandarizedErrorMessage (e );
52
53
throw new ConditionAwareException (
53
- e . getMessage () ,
54
+ message ,
54
55
e ,
55
56
KafkaCondition .Type .FoundKafkaById ,
56
57
KafkaCondition .Status .False ,
57
58
e .getClass ().getName (),
58
- e . getMessage () );
59
+ message );
59
60
}
60
61
}
61
62
62
63
public KafkaRequestList listKafkas (String accessToken ) throws ConditionAwareException {
63
64
try {
64
65
return createClient (accessToken ).listKafkas (null , null , null , null );
65
66
} catch (ApiException e ) {
67
+ String message = getStandarizedErrorMessage (e );
66
68
throw new ConditionAwareException (
67
- e . getMessage () ,
69
+ message ,
68
70
e ,
69
71
KafkaCondition .Type .UserKafkasUpToDate ,
70
72
KafkaCondition .Status .False ,
71
73
e .getClass ().getName (),
72
- e . getMessage () );
74
+ message );
73
75
}
74
76
}
75
77
@@ -81,13 +83,14 @@ public ServiceAccount createServiceAccount(
81
83
serviceAccountRequest .setName (spec .getServiceAccountName ());
82
84
return createClient (accessToken ).createServiceAccount (serviceAccountRequest );
83
85
} catch (ApiException e ) {
86
+ String message = getStandarizedErrorMessage (e );
84
87
throw new ConditionAwareException (
85
- e . getMessage () ,
88
+ message ,
86
89
e ,
87
90
KafkaCondition .Type .ServiceAccountCreated ,
88
91
KafkaCondition .Status .False ,
89
92
e .getClass ().getName (),
90
- e . getMessage () );
93
+ message );
91
94
}
92
95
}
93
96
@@ -133,4 +136,26 @@ public void createSecretForServiceAccount(
133
136
e .getMessage ());
134
137
}
135
138
}
139
+
140
+ private String getStandarizedErrorMessage (ApiException e ) {
141
+ if (e .getCode () == 504 ) {
142
+ return "Server timeout. Server is not responding" ;
143
+ }
144
+ if (e .getCode () == 500 ) {
145
+ return "Unknown server error." ;
146
+ }
147
+ if (e .getCode () == 500 ) {
148
+ return "Unknown server error." ;
149
+ }
150
+ if (e .getCode () == 400 ) {
151
+ return "Invalid request " + e .getMessage ();
152
+ }
153
+ if (e .getCode () == 401 ) {
154
+ return "Auth Token is invalid." ;
155
+ }
156
+ if (e .getCode () == 403 ) {
157
+ return "User not authorized to access the service" ;
158
+ }
159
+ return e .getMessage ();
160
+ }
136
161
}
0 commit comments