File tree Expand file tree Collapse file tree 3 files changed +23
-8
lines changed
src/main/java/com/prgmrs/voucher Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 11package com .prgmrs .voucher .global ;
22
3+ import com .prgmrs .voucher .exception .NoSuchVoucherTypeException ;
34import com .prgmrs .voucher .exception .WrongRangeFormatException ;
45import org .springframework .dao .DataAccessException ;
56import org .springframework .http .ResponseEntity ;
@@ -12,4 +13,14 @@ public class GlobalExceptionHandler {
1213 public ResponseEntity <String > handleException (Exception e ) {
1314 return ResponseEntity .badRequest ().body (e .getMessage ());
1415 }
16+
17+ @ ExceptionHandler (WrongRangeFormatException .class )
18+ public ResponseEntity <String > handleWrongRangeFormatException (WrongRangeFormatException e ) {
19+ return ResponseEntity .badRequest ().body ("invalid number was provided." );
20+ }
21+
22+ @ ExceptionHandler (NoSuchVoucherTypeException .class )
23+ public ResponseEntity <String > handleNoSuchVoucherTypeException (NoSuchVoucherTypeException e ) {
24+ return ResponseEntity .badRequest ().body (e .getMessage ());
25+ }
1526}
Original file line number Diff line number Diff line change 1+ package com .prgmrs .voucher .util ;
2+
3+ import java .util .UUID ;
4+
5+ public interface IdGenerator {
6+
7+ UUID generate ();
8+ }
Original file line number Diff line number Diff line change @@ -21,15 +21,11 @@ public enum ManagementType {
2121 }
2222
2323 public static ManagementType of (String orderNumberAsString ) {
24- try {
25- int orderNumber = Integer .parseInt (orderNumberAsString );
26- if (isWithinOrderNumberRange (orderNumber )) {
27- return ManagementType .values ()[orderNumber ];
28- }
29- throw new WrongRangeFormatException ("no such option exists" );
30- } catch (NumberFormatException e ) {
31- throw new WrongRangeFormatException ("input must be number" );
24+ int orderNumber = Integer .parseInt (orderNumberAsString );
25+ if (isWithinOrderNumberRange (orderNumber )) {
26+ return ManagementType .values ()[orderNumber ];
3227 }
28+ throw new WrongRangeFormatException ("no such option exists" );
3329 }
3430
3531 private static boolean isWithinOrderNumberRange (int orderNumber ) {
You can’t perform that action at this time.
0 commit comments