@@ -28,13 +28,16 @@ public class NaverUtil {
28
28
private String naverLocationSearchUrl ;
29
29
30
30
public List <LocationResponse > getLocationInfo (String location ) {
31
-
32
- NaverLocationResponse naverLocationResponse = locationSearch (NaverLocationRequest .of (location ));
33
-
31
+ NaverLocationResponse naverLocationResponse ;
32
+ try {
33
+ naverLocationResponse = locationSearch (NaverLocationRequest .of (location ));
34
+ } catch (RuntimeException e ) {
35
+ return List .of ();
36
+ }
34
37
return convertResponse (naverLocationResponse );
35
38
}
36
39
37
- private NaverLocationResponse locationSearch (NaverLocationRequest request ) {
40
+ private NaverLocationResponse locationSearch (NaverLocationRequest request ) throws RuntimeException {
38
41
URI uri = UriComponentsBuilder
39
42
.fromUriString (naverLocationSearchUrl )
40
43
.queryParams (request .toMap ())
@@ -50,22 +53,23 @@ private NaverLocationResponse locationSearch(NaverLocationRequest request) {
50
53
HttpEntity <Object > httpEntity = new HttpEntity <>(httpHeaders );
51
54
ParameterizedTypeReference <NaverLocationResponse > responseType = new ParameterizedTypeReference <>() {
52
55
};
53
-
54
- ResponseEntity <NaverLocationResponse > responseEntity = new RestTemplate ()
55
- .exchange (uri , HttpMethod .GET , httpEntity , responseType );
56
-
56
+ ResponseEntity <NaverLocationResponse > responseEntity ;
57
+
58
+ try {
59
+ responseEntity = new RestTemplate ()
60
+ .exchange (uri , HttpMethod .GET , httpEntity , responseType );
61
+ } catch (Exception e ) {
62
+ throw new RuntimeException ("Naver API 호출 중 오류가 발생했습니다." );
63
+ }
57
64
return responseEntity .getBody ();
58
65
}
59
66
60
67
private List <LocationResponse > convertResponse (NaverLocationResponse response ) {
61
-
62
68
List <NaverLocationResponse .SearchLocationItem > items = response .items ();
63
- List < LocationResponse > responseList = items
64
- .stream ()
69
+
70
+ return items .stream ()
65
71
.map (item -> new LocationResponse (convertX (item .getMapx ()), convertY (item .getMapy ()), trim (item .getTitle ()), trim (item .getAddress ()), trim (item .getRoadAddress ())))
66
72
.collect (Collectors .toList ());
67
-
68
- return responseList ;
69
73
}
70
74
private double convertX (int x ) {
71
75
0 commit comments