Skip to content

Commit 20bc0a0

Browse files
committed
[feat] Custom Exception Handling 추가 (Json Object Mapper error)
1 parent 5ec91fd commit 20bc0a0

File tree

5 files changed

+69
-33
lines changed

5 files changed

+69
-33
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package synopsis.graphql.excpetion;
2+
3+
public class JsonToObjectException extends RuntimeException {
4+
public JsonToObjectException(String message) {
5+
super(message);
6+
}
7+
8+
}

src/main/java/synopsis/graphql/util/converter/EuxpJsonToObjectConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JsonMappingException;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import lombok.extern.slf4j.Slf4j;
7+
import synopsis.graphql.excpetion.JsonToObjectException;
78
import synopsis.graphql.model.euxp.EuxpResult;
89

910
@Slf4j
@@ -23,7 +24,7 @@ public static EuxpResult convert(String jsonData) throws RuntimeException {
2324
} catch (JsonMappingException e) {
2425
e.printStackTrace();
2526
} catch (JsonProcessingException e) {
26-
throw new RuntimeException(e);
27+
throw new JsonToObjectException("Error found at " + e.getLocation() + " | EUXP Json Object Mapping Error : " + e.getMessage());
2728
}
2829
return null;
2930
}

src/main/java/synopsis/graphql/util/converter/ScsJsonToObjectConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import lombok.extern.slf4j.Slf4j;
6+
import synopsis.graphql.excpetion.JsonToObjectException;
67
import synopsis.graphql.model.scs.ScsResult;
78

89
@Slf4j
@@ -18,7 +19,7 @@ public static ScsResult convert(String jsonData) throws RuntimeException {
1819
try {
1920
return objectMapper.readValue(jsonData, ScsResult.class);
2021
} catch (JsonProcessingException e) {
21-
throw new RuntimeException(e);
22+
throw new JsonToObjectException("Error found at " + e.getLocation() + " | SCS Json Object Mapping Error : " + e.getMessage());
2223
}
2324
}
2425
}

src/main/java/synopsis/graphql/util/converter/SmdJsonToObjectConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JsonMappingException;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import lombok.extern.slf4j.Slf4j;
7+
import synopsis.graphql.excpetion.JsonToObjectException;
78
import synopsis.graphql.model.smd.SmdResult;
89

910
@Slf4j
@@ -23,7 +24,7 @@ public static SmdResult convert(String jsonData) throws RuntimeException {
2324
} catch (JsonMappingException e) {
2425
e.printStackTrace();
2526
} catch (JsonProcessingException e) {
26-
throw new RuntimeException(e);
27+
throw new JsonToObjectException("Error found at " + e.getLocation() + " | SMD Json Object Mapping Error : " + e.getMessage());
2728
}
2829
return null;
2930
}

src/main/java/synopsis/graphql/util/converter/ViewPageConverter.java

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,47 @@ private static UserContentsPreference getUserContentsPreference(SmdResult smdRes
133133

134134

135135
private static PlayInfo getPlayInfo(Contents euxpContents) {
136+
137+
MainPreviewPlay mainPreviewPlay = getMainPreviewPlay(euxpContents);
138+
TrailerPlay trailerPlay = getTrailerPlay(euxpContents);
139+
AIHighlightPlay aiHighlightPlay = getAiHighlightPlay(euxpContents);
140+
List<CornerPlay> cornerPlays = getCornerPlays(euxpContents);
141+
List<SpecialPlay> specialPlays = getSpecialPlays(euxpContents);
142+
143+
return PlayInfo.builder()
144+
.mainPreviewPlay(mainPreviewPlay)
145+
.trailerPlay(trailerPlay)
146+
.aiHighlightPlay(aiHighlightPlay)
147+
.cornerPlays(cornerPlays)
148+
.specialPlays(specialPlays)
149+
.build();
150+
}
151+
152+
private static TrailerPlay getTrailerPlay(Contents euxpContents) {
153+
return TrailerPlay.builder()
154+
.episodeId(euxpContents.epsd_id)
155+
.seriesId(euxpContents.sris_id)
156+
.productPriceId(euxpContents.preview.get(FIRST_INDEX).prd_prc_id)
157+
.build();
158+
}
159+
160+
private static MainPreviewPlay getMainPreviewPlay(Contents euxpContents) {
136161
List<EpsdRsluInfo> sortedEpsdRsluInfo = euxpContents.epsd_rslu_info.stream()
137162
.sorted(Comparator.comparing(e -> e.rslu_typ_cd))
138163
.toList();
139164
EpsdRsluInfo epsdRsluInfo = sortedEpsdRsluInfo.get(FIRST_INDEX);
140165

141-
MainPreviewPlay mainPreviewPlay = MainPreviewPlay.builder()
166+
return MainPreviewPlay.builder()
142167
.episodeId(euxpContents.epsd_id)
143168
.seriesId(euxpContents.sris_id)
144169
.episodeResolutionId(epsdRsluInfo.epsd_rslu_id)
145170
.startTime((int) epsdRsluInfo.openg_tmtag_tmsc)
146171
.previewTime(Integer.parseInt(epsdRsluInfo.preview_time))
147172
.totalTime(Integer.parseInt(euxpContents.play_time))
148173
.build();
174+
}
149175

150-
TrailerPlay trailerPlay = TrailerPlay.builder()
151-
.episodeId(euxpContents.epsd_id)
152-
.seriesId(euxpContents.sris_id)
153-
.productPriceId(euxpContents.preview.get(FIRST_INDEX).prd_prc_id)
154-
.build();
155-
176+
private static AIHighlightPlay getAiHighlightPlay(Contents euxpContents) {
156177
AIHighlightPlay aiHighlightPlay;
157178
if (euxpContents.ai_inside_scenes.isEmpty()) {
158179
aiHighlightPlay = null;
@@ -164,23 +185,10 @@ private static PlayInfo getPlayInfo(Contents euxpContents) {
164185
.previewTime(PREVIEW_TIME_FIXED)
165186
.build();
166187
}
167-
var corners = euxpContents.corners;
168-
List<CornerPlay> cornerPlays = Collections.emptyList();
169-
if (corners != null && (!euxpContents.corners.isEmpty())) {
170-
cornerPlays = euxpContents.corners.stream()
171-
.map(corner ->
172-
CornerPlay.builder()
173-
.cornerBottomName(corner.cnr_btm_nm)
174-
.cornerGroupName(corner.cnr_grp_id)
175-
.cornerId(corner.cnr_id)
176-
.cornerName(corner.cnr_nm)
177-
.episodeResolutionId(corner.epsd_rslu_id)
178-
.imagePath(corner.img_path)
179-
.build())
180-
.collect(Collectors.toCollection(ArrayList::new));
181-
182-
}
188+
return aiHighlightPlay;
189+
}
183190

191+
private static List<SpecialPlay> getSpecialPlays(Contents euxpContents) {
184192
List<SpecialPlay> specialPlays = Collections.emptyList();
185193
if (!euxpContents.special.isEmpty()) {
186194
specialPlays = euxpContents.special.stream()
@@ -193,15 +201,32 @@ private static PlayInfo getPlayInfo(Contents euxpContents) {
193201
.build())
194202
.collect(Collectors.toCollection(ArrayList::new));
195203
}
204+
return specialPlays;
205+
}
196206

207+
private static List<CornerPlay> getCornerPlays(Contents euxpContents) {
208+
var corners = euxpContents.corners;
209+
List<CornerPlay> cornerPlays = Collections.emptyList();
210+
if (corners != null && (!euxpContents.corners.isEmpty())) {
211+
cornerPlays = getCornerPlayList(euxpContents);
212+
}
213+
return cornerPlays;
214+
}
197215

198-
return PlayInfo.builder()
199-
.mainPreviewPlay(mainPreviewPlay)
200-
.trailerPlay(trailerPlay)
201-
.aiHighlightPlay(aiHighlightPlay)
202-
.cornerPlays(cornerPlays)
203-
.specialPlays(specialPlays)
204-
.build();
216+
private static List<CornerPlay> getCornerPlayList(Contents euxpContents) {
217+
List<CornerPlay> cornerPlays;
218+
cornerPlays = euxpContents.corners.stream()
219+
.map(corner ->
220+
CornerPlay.builder()
221+
.cornerBottomName(corner.cnr_btm_nm)
222+
.cornerGroupName(corner.cnr_grp_id)
223+
.cornerId(corner.cnr_id)
224+
.cornerName(corner.cnr_nm)
225+
.episodeResolutionId(corner.epsd_rslu_id)
226+
.imagePath(corner.img_path)
227+
.build())
228+
.collect(Collectors.toCollection(ArrayList::new));
229+
return cornerPlays;
205230
}
206231

207232
private static ContentsEpisodeList getContentsEpisodeList(Contents euxpContents) {

0 commit comments

Comments
 (0)