1616
1717package io .swagger .petstore .controller ;
1818
19+ import com .bugsnag .Bugsnag ;
1920import io .swagger .oas .inflector .models .RequestContext ;
2021import io .swagger .oas .inflector .models .ResponseContext ;
2122import io .swagger .petstore .data .PetData ;
3334public class PetController {
3435
3536 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+ }
3647
3748 public ResponseContext findPetsByStatus (final RequestContext request , final String status ) {
3849 if (status == null ) {
50+ bugsnag .notify (new RuntimeException ("No status provided" ));
3951 return new ResponseContext ()
4052 .status (Response .Status .BAD_REQUEST )
4153 .entity ("No status provided. Try again?" );
@@ -44,16 +56,19 @@ public ResponseContext findPetsByStatus(final RequestContext request, final Stri
4456 final List <Pet > petByStatus = petData .findPetByStatus (status );
4557
4658 if (petByStatus == null ) {
59+ bugsnag .notify (new RuntimeException ("Pets not found" ));
4760 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pets not found" );
4861 }
4962
63+ bugsnag .notify (new RuntimeException ("Pets not found" ));
5064 return new ResponseContext ()
5165 .contentType (Util .getMediaType (request ))
5266 .entity (petByStatus );
5367 }
5468
5569 public ResponseContext getPetById (final RequestContext request , final Long petId ) {
5670 if (petId == null ) {
71+ bugsnag .notify (new RuntimeException ("No petId provided" ));
5772 return new ResponseContext ()
5873 .status (Response .Status .BAD_REQUEST )
5974 .entity ("No petId provided. Try again?" );
@@ -67,17 +82,20 @@ public ResponseContext getPetById(final RequestContext request, final Long petId
6782 .entity (pet );
6883 }
6984
85+ bugsnag .notify (new RuntimeException ("Pets not found" ));
7086 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
7187 }
7288
7389 public ResponseContext updatePetWithForm (final RequestContext request , final Long petId , final String name , final String status ) {
7490 if (petId == null ) {
91+ bugsnag .notify (new RuntimeException ("No petId provided" ));
7592 return new ResponseContext ()
7693 .status (Response .Status .BAD_REQUEST )
7794 .entity ("No Pet provided. Try again?" );
7895 }
7996
8097 if (name == null ) {
98+ bugsnag .notify (new RuntimeException ("No name provided" ));
8199 return new ResponseContext ()
82100 .status (Response .Status .BAD_REQUEST )
83101 .entity ("No Name provided. Try again?" );
@@ -87,6 +105,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
87105 final Pet existingPet = petData .getPetById (petId );
88106
89107 if (existingPet == null ) {
108+ bugsnag .notify (new RuntimeException ("No pet provided" ));
90109 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
91110 }
92111
@@ -102,6 +121,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
102121
103122 public ResponseContext deletePet (final RequestContext request , final String apiKey , final Long petId ) {
104123 if (petId == null ) {
124+ bugsnag .notify (new RuntimeException ("No petId provided" ));
105125 return new ResponseContext ()
106126 .status (Response .Status .BAD_REQUEST )
107127 .entity ("No petId provided. Try again?" );
@@ -118,24 +138,28 @@ public ResponseContext deletePet(final RequestContext request, final String apiK
118138 .contentType (outputType )
119139 .entity ("Pet deleted" );
120140 } else {
141+ bugsnag .notify (new RuntimeException ("Pet couldn't be deleted" ));
121142 return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be deleted." );
122143 }
123144
124145 }
125146
126147 public ResponseContext uploadFile (final RequestContext request , final Long petId , final String apiKey , final File file ) {
127148 if (petId == null ) {
149+ bugsnag .notify (new RuntimeException ("No petId provided" ));
128150 return new ResponseContext ()
129151 .status (Response .Status .BAD_REQUEST )
130152 .entity ("No petId provided. Try again?" );
131153 }
132154
133155 if (file == null ) {
156+ bugsnag .notify (new RuntimeException ("No file provided" ));
134157 return new ResponseContext ().status (Response .Status .BAD_REQUEST ).entity ("No file uploaded" );
135158 }
136159
137160 final Pet existingPet = petData .getPetById (petId );
138161 if (existingPet == null ) {
162+ bugsnag .notify (new RuntimeException ("No pet provided" ));
139163 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
140164 }
141165
@@ -150,12 +174,14 @@ public ResponseContext uploadFile(final RequestContext request, final Long petId
150174 .contentType (Util .getMediaType (request ))
151175 .entity (pet );
152176 } else {
177+ bugsnag .notify (new RuntimeException ("Pet couldn't be updated" ));
153178 return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be updated." );
154179 }
155180 }
156181
157182 public ResponseContext addPet (final RequestContext request , final Pet pet ) {
158183 if (pet == null ) {
184+ bugsnag .notify (new RuntimeException ("No pet provided" ));
159185 return new ResponseContext ()
160186 .status (Response .Status .BAD_REQUEST )
161187 .entity ("No Pet provided. Try again?" );
@@ -176,13 +202,15 @@ public ResponseContext addPet(final RequestContext request, final Long id, final
176202
177203 public ResponseContext updatePet (final RequestContext request , final Pet pet ) {
178204 if (pet == null ) {
205+ bugsnag .notify (new RuntimeException ("No pet provided" ));
179206 return new ResponseContext ()
180207 .status (Response .Status .BAD_REQUEST )
181208 .entity ("No Pet provided. Try again?" );
182209 }
183210
184211 final Pet existingPet = petData .getPetById (pet .getId ());
185212 if (existingPet == null ) {
213+ bugsnag .notify (new RuntimeException ("No pet provided" ));
186214 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
187215 }
188216
@@ -202,6 +230,7 @@ public ResponseContext updatePet(final RequestContext request, final Long id, fi
202230
203231 public ResponseContext findPetsByTags (final RequestContext request , final List <String > tags ) {
204232 if (tags == null || tags .size () == 0 ) {
233+ bugsnag .notify (new RuntimeException ("No tags provided" ));
205234 return new ResponseContext ()
206235 .status (Response .Status .BAD_REQUEST )
207236 .entity ("No tags provided. Try again?" );
0 commit comments