@@ -61,7 +61,7 @@ public CarService(String email, String password) {
6161 *
6262 * @param vin The VIN of the car.
6363 * @return A {@link CarCoolingInfo} object containing the cooling information of the car.
64- * @throws RuntimeException If an error occurs while retrieving the cooling status.
64+ * @throws CarServiceException If an error occurs while retrieving the cooling status.
6565 */
6666 public CarCoolingInfo getCooling (String vin ) {
6767 try {
@@ -71,7 +71,7 @@ public CarCoolingInfo getCooling(String vin) {
7171 cooling .getClimatisationDuration (), cooling .getStartMode (), cooling .getHeaterMode (), mapToCarReport (cooling .getReport ()),
7272 cooling .getTimers ().stream ().map (this ::mapToCarCoolingTimer ).toList ());
7373 } catch (ApiException e ) {
74- throw new RuntimeException ( e );
74+ throw new CarServiceException ( "Failed to get cooling information" , e . getMessage () );
7575 }
7676 }
7777
@@ -81,11 +81,11 @@ public CarCoolingInfo getCooling(String vin) {
8181 * @param vin The VIN of the car.
8282 * @param duration The duration to flash the lights (in seconds).
8383 * @return The status of the request.
84- * @throws RuntimeException If the duration exceeds the maximum allowed or if an error occurs.
84+ * @throws CarServiceException If the duration exceeds the maximum allowed or if an error occurs.
8585 */
8686 public String flash (String vin , Integer duration ) {
8787 if (duration > 30 ) {
88- throw new RuntimeException ( "maximum duration is 30 " );
88+ throw new CarServiceException ( "Failed to flash lights" , " duration limit exceeded, max 30 minutes " );
8989 }
9090 CarLocation location = getLocation (vin );
9191 FlashWebRequestResource flashWebRequestResource = new FlashWebRequestResource ();
@@ -96,7 +96,7 @@ public String flash(String vin, Integer duration) {
9696 try {
9797 return flashApi .flash (vin , flashWebRequestResource ).getStatus ();
9898 } catch (ApiException e ) {
99- throw new RuntimeException ( e );
99+ throw new CarServiceException ( "Failed to flash lights" , e . getMessage () );
100100 }
101101 }
102102
@@ -106,11 +106,11 @@ public String flash(String vin, Integer duration) {
106106 * @param vin The VIN of the car.
107107 * @param duration The duration to honk the horn (in seconds).
108108 * @return The status of the request.
109- * @throws RuntimeException If the duration exceeds the maximum allowed or if an error occurs.
109+ * @throws CarServiceException If the duration exceeds the maximum allowed or if an error occurs.
110110 */
111111 public String honk (String vin , Integer duration ) {
112112 if (duration > 30 ) {
113- throw new RuntimeException ( "maximum duration is 30 " );
113+ throw new CarServiceException ( "Failed to honk horn" , " duration limit exceeded, max 30 minutes " );
114114 }
115115 CarLocation location = getLocation (vin );
116116 HonkWebRequestResource honkWebRequestResource = new HonkWebRequestResource ();
@@ -121,7 +121,7 @@ public String honk(String vin, Integer duration) {
121121 try {
122122 return honkApi .honk (vin , honkWebRequestResource ).getStatus ();
123123 } catch (ApiException e ) {
124- throw new RuntimeException ( e );
124+ throw new CarServiceException ( "Failed to honk horn" , e . getMessage () );
125125 }
126126 }
127127
@@ -131,14 +131,14 @@ public String honk(String vin, Integer duration) {
131131 * @param vin The VIN of the car.
132132 * @param id The id of the request.
133133 * @return The status of the request.
134- * @throws RuntimeException If an error occurs while retrieving the request status.
134+ * @throws CarServiceException If an error occurs while retrieving the request status.
135135 */
136136 public String getRequest (String vin , String id ) {
137137 try {
138138 RequestWebResponseResource request = requestApi .getRequest (vin , id );
139139 return request .getStatus ();
140140 } catch (ApiException e ) {
141- throw new RuntimeException ( e );
141+ throw new CarServiceException ( "Failed to get request" , e . getMessage () );
142142 }
143143 }
144144
@@ -147,14 +147,14 @@ public String getRequest(String vin, String id) {
147147 *
148148 * @param vin The VIN of the car.
149149 * @return A {@link CarStatus} object containing the status information of the car.
150- * @throws RuntimeException If an error occurs while retrieving the car status.
150+ * @throws CarServiceException If an error occurs while retrieving the car status.
151151 */
152152 public CarStatus getStatus (String vin ) {
153153 try {
154154 StatusWebResponseResource status = statusApi .getStatus (vin );
155155 return new CarStatus (status .getVin (), status .getData ().stream ().map (this ::mapToCarData ).toList ());
156156 } catch (ApiException e ) {
157- throw new RuntimeException ( e );
157+ throw new CarServiceException ( "Failed to get status" , e . getMessage () );
158158 }
159159 }
160160
@@ -165,11 +165,11 @@ public CarStatus getStatus(String vin) {
165165 * @param pin The pin used to authenticate the ventilator action.
166166 * @param duration The duration to run the ventilator (in seconds).
167167 * @return The ventilator status ID.
168- * @throws RuntimeException If the duration exceeds the maximum allowed or if an error occurs.
168+ * @throws CarServiceException If the duration exceeds the maximum allowed or if an error occurs.
169169 */
170170 public String startVentilator (String vin , String pin , Integer duration ) {
171171 if (duration > 30 ) {
172- throw new RuntimeException ( "maximum duration is 30 " );
172+ throw new CarServiceException ( "Failed to start ventilator" , " duration limit exceeded, max 30 minutes " );
173173 }
174174
175175 VentilatorWebRequestResource ventilatorWebRequestResource = new VentilatorWebRequestResource ();
@@ -180,7 +180,7 @@ public String startVentilator(String vin, String pin, Integer duration) {
180180 VentilatorWebResponseResource ventilatorStatus = ventilatorApi .startVentilator (vin , ventilatorWebRequestResource );
181181 return ventilatorStatus .getId ();
182182 } catch (ApiException e ) {
183- throw new RuntimeException ( e );
183+ throw new CarServiceException ( "Failed to start ventilator" , e . getMessage () );
184184 }
185185 }
186186
@@ -190,7 +190,7 @@ public String startVentilator(String vin, String pin, Integer duration) {
190190 * @param vin The VIN of the car.
191191 * @param pin The pin used to authenticate the ventilator action.
192192 * @return The ventilator status ID.
193- * @throws RuntimeException If an error occurs while stopping the ventilator.
193+ * @throws CarServiceException If an error occurs while stopping the ventilator.
194194 */
195195 public String stopVentilator (String vin , String pin ) {
196196 VentilatorWebRequestResource ventilatorWebRequestResource = new VentilatorWebRequestResource ();
@@ -201,7 +201,7 @@ public String stopVentilator(String vin, String pin) {
201201 VentilatorWebResponseResource ventilatorStatus = ventilatorApi .stopVentilator (vin , ventilatorWebRequestResource );
202202 return ventilatorStatus .getId ();
203203 } catch (ApiException e ) {
204- throw new RuntimeException ( e );
204+ throw new CarServiceException ( "Failed to stop ventilator" , e . getMessage () );
205205 }
206206 }
207207
@@ -210,14 +210,14 @@ public String stopVentilator(String vin, String pin) {
210210 *
211211 * @param vin The VIN of the car.
212212 * @return A {@link CarLocation} object representing the car's location.
213- * @throws RuntimeException If an error occurs while retrieving the car location.
213+ * @throws CarServiceException If an error occurs while retrieving the car location.
214214 */
215215 public CarLocation getLocation (String vin ) {
216216 try {
217217 LocationWebResponseResource location = locationApi .getLocation (vin );
218218 return new CarLocation (location .getLatitude (), location .getLongitude ());
219219 } catch (ApiException e ) {
220- throw new RuntimeException ( e );
220+ throw new CarServiceException ( "Failed to get car location" , e . getMessage () );
221221 }
222222 }
223223
0 commit comments