SWM-99-degree / jariBean

SWM 14th JariBean Project
0 stars 1 forks source link

bug <๊น€์ƒํ˜„ #253> modify null exception handler #254

Closed isayaksh closed 1 year ago

isayaksh commented 1 year ago

๐Ÿ”ฅ ๋ฌธ์ œ

์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๊ฐฑ์‹ ํ•  ๋•Œ image, nickname, description์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ์šฉ์ž ์ธก์—์„œ ๋งŒ์•ฝ nickname์— ๋Œ€ํ•œ ์ •๋ณด๋งŒ์„ ์ˆ˜์ •ํ•  ๋•Œ ๋‚˜๋จธ์ง€ image, description์— ๋Œ€ํ•œ ์ •๋ณด๋Š” Null๋กœ ์ „๋‹ฌ๋œ๋‹ค. ๋งŒ์•ฝ Null๋กœ ์ •๋ณด๊ฐ€ ์ „๋‹ฌ๋œ๋‹ค๋ฉด ํ•ด๋‹น ์ •๋ณด๋Š” ์ˆ˜์ •ํ•˜์ง€ ์•Š๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•œ๋‹ค.

Exception Handler

2023-11-03 03:09:47.400 ERROR 1 --- [nio-8080-exec-2] c.e.j.handler.CustomExceptionHandler     :
 Cannot invoke "org.springframework.web.multipart.MultipartFile.isEmpty()" because "imageFile" is null

ํ•˜์ง€๋งŒ ํ˜„์žฌ MultipartFile ๊ฐ์ฒด๊ฐ€ ๋น„์–ด์žˆ๋Š” ์ƒํƒœ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋กœ์ง์ธ isEmpty() ๋ฉ”์„œ๋„๋Š” ์กด์žฌํ•˜์ง€๋งŒ ๊ฐ์ฒด ์ž์ฒด๊ฐ€ Null์ธ ๊ฒƒ์„ ํ™•์ธํ•˜๋Š” ๋กœ์ง์€ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•˜๋‹ค.

๋”ฐ๋ผ์„œ ํ•ด๋‹น ๋กœ์ง์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ •์ƒ์ ์œผ๋กœ ์ •๋ณด๊ฐ€ ์ˆ˜์ •๋  ์ˆ˜ ์žˆ๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.

๐Ÿ›  ์ˆ˜์ •์‚ฌํ•ญ

MultipartFile ์ž์ฒด๊ฐ€ Null์ผ ๊ฒฝ์šฐ๋„ ๊ณ ๋ คํ•˜์—ฌ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๋กœ์ง์„ ์ˆ˜์ •ํ•˜์˜€๋‹ค.

์ˆ˜์ • ์ „

// MultipartFile์˜ ๊ฐ’์ด null์ผ ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
if(imageFile.isEmpty()) {
    return S3ImageResDto.builder()
            .imageUrl(null)
            .build();
}

์ˆ˜์ • ํ›„

// MultipartFile์˜ ๊ฐ’์ด null์ผ ๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
if(imageFile == null || imageFile.isEmpty()) {
    return S3ImageResDto.builder()
            .imageUrl(null)
            .build();
}