16
16
17
17
package io .swagger .petstore .controller ;
18
18
19
+ import com .bugsnag .Bugsnag ;
19
20
import io .swagger .oas .inflector .models .RequestContext ;
20
21
import io .swagger .oas .inflector .models .ResponseContext ;
21
22
import io .swagger .petstore .data .PetData ;
33
34
public class PetController {
34
35
35
36
private static PetData petData = new PetData ();
37
+ private static Bugsnag bugsnag ;
38
+
39
+ static {
40
+ String bugsnagApiKey = System .getenv ("BUGSNAG_API_KEY" );
41
+ if (bugsnagApiKey != null ) {
42
+ bugsnag = new Bugsnag (bugsnagApiKey );
43
+ } else {
44
+ throw new IllegalStateException ("BUGSNAG_API_KEY environment variable is not set" );
45
+ }
46
+ }
36
47
37
48
public ResponseContext findPetsByStatus (final RequestContext request , final String status ) {
38
49
if (status == null ) {
50
+ bugsnag .notify (new RuntimeException ("No status provided" ));
39
51
return new ResponseContext ()
40
52
.status (Response .Status .BAD_REQUEST )
41
53
.entity ("No status provided. Try again?" );
@@ -44,16 +56,19 @@ public ResponseContext findPetsByStatus(final RequestContext request, final Stri
44
56
final List <Pet > petByStatus = petData .findPetByStatus (status );
45
57
46
58
if (petByStatus == null ) {
59
+ bugsnag .notify (new RuntimeException ("Pets not found" ));
47
60
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pets not found" );
48
61
}
49
62
63
+ bugsnag .notify (new RuntimeException ("Pets not found" ));
50
64
return new ResponseContext ()
51
65
.contentType (Util .getMediaType (request ))
52
66
.entity (petByStatus );
53
67
}
54
68
55
69
public ResponseContext getPetById (final RequestContext request , final Long petId ) {
56
70
if (petId == null ) {
71
+ bugsnag .notify (new RuntimeException ("No petId provided" ));
57
72
return new ResponseContext ()
58
73
.status (Response .Status .BAD_REQUEST )
59
74
.entity ("No petId provided. Try again?" );
@@ -67,17 +82,20 @@ public ResponseContext getPetById(final RequestContext request, final Long petId
67
82
.entity (pet );
68
83
}
69
84
85
+ bugsnag .notify (new RuntimeException ("Pets not found" ));
70
86
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
71
87
}
72
88
73
89
public ResponseContext updatePetWithForm (final RequestContext request , final Long petId , final String name , final String status ) {
74
90
if (petId == null ) {
91
+ bugsnag .notify (new RuntimeException ("No petId provided" ));
75
92
return new ResponseContext ()
76
93
.status (Response .Status .BAD_REQUEST )
77
94
.entity ("No Pet provided. Try again?" );
78
95
}
79
96
80
97
if (name == null ) {
98
+ bugsnag .notify (new RuntimeException ("No name provided" ));
81
99
return new ResponseContext ()
82
100
.status (Response .Status .BAD_REQUEST )
83
101
.entity ("No Name provided. Try again?" );
@@ -87,6 +105,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
87
105
final Pet existingPet = petData .getPetById (petId );
88
106
89
107
if (existingPet == null ) {
108
+ bugsnag .notify (new RuntimeException ("No pet provided" ));
90
109
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
91
110
}
92
111
@@ -102,6 +121,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
102
121
103
122
public ResponseContext deletePet (final RequestContext request , final String apiKey , final Long petId ) {
104
123
if (petId == null ) {
124
+ bugsnag .notify (new RuntimeException ("No petId provided" ));
105
125
return new ResponseContext ()
106
126
.status (Response .Status .BAD_REQUEST )
107
127
.entity ("No petId provided. Try again?" );
@@ -118,24 +138,28 @@ public ResponseContext deletePet(final RequestContext request, final String apiK
118
138
.contentType (outputType )
119
139
.entity ("Pet deleted" );
120
140
} else {
141
+ bugsnag .notify (new RuntimeException ("Pet couldn't be deleted" ));
121
142
return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be deleted." );
122
143
}
123
144
124
145
}
125
146
126
147
public ResponseContext uploadFile (final RequestContext request , final Long petId , final String apiKey , final File file ) {
127
148
if (petId == null ) {
149
+ bugsnag .notify (new RuntimeException ("No petId provided" ));
128
150
return new ResponseContext ()
129
151
.status (Response .Status .BAD_REQUEST )
130
152
.entity ("No petId provided. Try again?" );
131
153
}
132
154
133
155
if (file == null ) {
156
+ bugsnag .notify (new RuntimeException ("No file provided" ));
134
157
return new ResponseContext ().status (Response .Status .BAD_REQUEST ).entity ("No file uploaded" );
135
158
}
136
159
137
160
final Pet existingPet = petData .getPetById (petId );
138
161
if (existingPet == null ) {
162
+ bugsnag .notify (new RuntimeException ("No pet provided" ));
139
163
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
140
164
}
141
165
@@ -150,12 +174,14 @@ public ResponseContext uploadFile(final RequestContext request, final Long petId
150
174
.contentType (Util .getMediaType (request ))
151
175
.entity (pet );
152
176
} else {
177
+ bugsnag .notify (new RuntimeException ("Pet couldn't be updated" ));
153
178
return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be updated." );
154
179
}
155
180
}
156
181
157
182
public ResponseContext addPet (final RequestContext request , final Pet pet ) {
158
183
if (pet == null ) {
184
+ bugsnag .notify (new RuntimeException ("No pet provided" ));
159
185
return new ResponseContext ()
160
186
.status (Response .Status .BAD_REQUEST )
161
187
.entity ("No Pet provided. Try again?" );
@@ -176,13 +202,15 @@ public ResponseContext addPet(final RequestContext request, final Long id, final
176
202
177
203
public ResponseContext updatePet (final RequestContext request , final Pet pet ) {
178
204
if (pet == null ) {
205
+ bugsnag .notify (new RuntimeException ("No pet provided" ));
179
206
return new ResponseContext ()
180
207
.status (Response .Status .BAD_REQUEST )
181
208
.entity ("No Pet provided. Try again?" );
182
209
}
183
210
184
211
final Pet existingPet = petData .getPetById (pet .getId ());
185
212
if (existingPet == null ) {
213
+ bugsnag .notify (new RuntimeException ("No pet provided" ));
186
214
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
187
215
}
188
216
@@ -202,6 +230,7 @@ public ResponseContext updatePet(final RequestContext request, final Long id, fi
202
230
203
231
public ResponseContext findPetsByTags (final RequestContext request , final List <String > tags ) {
204
232
if (tags == null || tags .size () == 0 ) {
233
+ bugsnag .notify (new RuntimeException ("No tags provided" ));
205
234
return new ResponseContext ()
206
235
.status (Response .Status .BAD_REQUEST )
207
236
.entity ("No tags provided. Try again?" );
0 commit comments