Anazinza / yeolsimhihargeyo

๐Ÿ™
0 stars 0 forks source link

โš  Exception Handler #7

Open jongeuni opened 2 years ago

jongeuni commented 2 years ago

Exception Handling in GraphQL

Exception Handling in Login (Rest api)

jongeuni commented 2 years ago
{
    "errors": [
        {
            "message": "Exception while fetching data (/createAccount) : email already exist",
            "locations": [
                {
                    "line": 2,
                    "column": 5
                }
            ],
            "path": [
                "createAccount"
            ],
            "extensions": {
                "code": 400,
                "message": "email already exist",
                "classification": "DataFetchingException"
            }
        }
    ],
    "data": {
        "createAccount": null
    }
}

ํ˜„์žฌ ์ด๋Ÿฐ ์‹์œผ๋กœ ์‘๋‹ต์ด ์˜จ๋‹ค. ์œ„์— ์ ์—ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ Response Status๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์œผ๋ฉด ์ข‹๊ฒ ์ง€๋งŒ ๊ธ€๋“ค์„ ๋ณด์•˜์„ ๋•Œ 200OK๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

jongeuni commented 2 years ago
{
    "status": 400,
    "message": "password mismatch",
}

์›๋ž˜ ์ด๋ ‡๊ฒŒ๋งŒ ์‘๋‹ต ์ฃผ์—ˆ์—ˆ๋Š”๋ฐ

{
    "status": 400,
    "message": "password mismatch",
    "detailsMessage": "์กด์žฌํ•˜๋Š” ์ด๋ฉ”์ผ์ด์ง€๋งŒ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.",
    "stack": "Optional[com.dsm.spotemo.rest.LoginService.login(LoginService.java:23)]"
}

์ด๋Ÿฐ์‹์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ๋‹ค. stack์˜ ๊ฒฝ์šฐ e.getStackTrace()์„ ์ฐ์—ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ธด ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ๊ฐ’๋งŒ ๋นผ๋ƒˆ๋‹ค.