본문 바로가기
C.W.K.
Stream
Lesson 05 of 07 · published

오류 메시지

~9 min · protocol, errors

Level 0Poller
0 XP0/60 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

오류는 예외가 아니라 데이터야

프로토콜의 오류도 자료형이 있는 봉투, 기계가 읽을 코드, 사람이 읽을 문장을 담은 평범한 메시지야. 클라이언트 UI 는 코드에 따라 토스트, 대화 상자, 이동 같은 동작을 골라. 오류 형식도 공개 API 의 일부이므로 한 번 정한 뒤 안정적으로 유지해야 해.

6가지 표준 코드

invalid_message, unauthorized, forbidden, not_found, rate_limited, internal_error 여섯 개면 REST 의 오류 어휘 대부분을 WebSocket 으로 옮길 수 있어. 필요하다면 room_full 이나 session_expired 같은 앱 전용 코드를 더하되 배포 버전 사이에서 의미를 안정적으로 유지해.

Code

오류 봉투·json
{
  "type":    "error",
  "code":    "rate_limited",
  "message": "you're sending too fast, slow down",
  "details": {
    "retry_after": 5,
    "limit":       "20 messages/second"
  },
  "ref_id":  "abc-123"
}
표준 오류 코드·text
invalid_message   - message did not match envelope or schema
unauthorized      - missing or invalid auth
forbidden         - authenticated but not permitted
not_found         - referenced room/user/resource does not exist
rate_limited      - too many messages too fast
internal_error    - server-side bug or unexpected failure

External links

Exercise

채팅 앱에 여섯 줄짜리 오류 코드 표를 정의해. 코드마다 서버의 발생 조건, UI 에 보일 문장, 클라이언트의 동작(토스트, 대화 상자, 이동, 조용한 재시도) 을 적고 프로토콜 명세에 표로 문서화해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.