[Spring] Error 처리

유존돌돌이·2022년 4월 9일
0

Spring

목록 보기
25/26
post-thumbnail

Error Page 처리

BasicErrorController 의 처리 뷰 선택 우선순위

Spring 지원 기본 error template => /error/~
-> Override 해서 경로 수정 후 사용 가능.

  1. 뷰템플릿

    • resources/templates/error/500.html
    • resources/templates/error/5xx.html
  2. 정적리소스(static,public)

    • resources/static/error/400.html
    • resources/static/error/404.html
    • resources/static/error/4xx.html
  3. 적용 대상이 없을 때 뷰 이름(error)

    • resources/templates/error.html

API 에러처리

에러처리를 따로 해주지 않는다면 만약 json Rest API통신을 할 때 에러가 발생할 경우 에러 페이지를 리턴한다.
하지만 JSON통신에서는 페이지의 html을 해석할 수 없기 때문에 이를 처리해줘야한다.

0개의 댓글