Skip to main content

에러 응답

#HTTP 상태 코드

코드의미
200성공
400쿼리 검증 실패, 또는 요청 내용이 서로 맞지 않음
404자원이 존재하지 않음
429레이트 리밋 초과
500서버 오류

#응답 envelope

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": [
    "outcomeId must be a string",
    "outcomeId should not be empty"
  ]
}
필드설명
statusCodeHTTP 상태와 동일한 숫자
error짧은 사람용 라벨 ("Bad Request", "Not Found"). 429 와 500 에는 없습니다.
messagestring 또는 string[]. 쿼리 검증 실패는 배열이고, 핸들러가 직접 내는 에러(호가창의 outcomeId 누락, 존재하지 않는 시장)는 문자열 하나입니다.
message 가 배열일 수 있다는 점

요청 검증기의 검증 실패는 message: string[] 로 옵니다. 단순히 error.message 를 한 줄로 보여주면 안 되고, 배열의 각 원소를 별도로 렌더링하세요.

#클라이언트에서 처리하는 패턴

type ApiError = {
  statusCode: number;
  error?: string;
  message: string | string[];
};
 
async function call() {
  const res = await fetch(url, init);
  if (!res.ok) {
    const err = (await res.json()) as ApiError;
    const messages = Array.isArray(err.message) ? err.message : [err.message];
    throw new Error(messages.join('\n'));
  }
  return res.json();
}

#자주 만나는 시나리오

상황응답
호가창에서 outcomeId 누락400 + "outcomeId is required"
시계열 가격에서 outcomeId 누락400 + ["outcomeId must be a string", "outcomeId should not be empty"]
잘못된 enum 값400 + ["status must be one of the following values: ACTIVE, RESOLVED, CANCELLED"]
정의되지 않은 쿼리 파라미터400 + ["property foo should not exist"]
시장이 없음404 + "Market not found: <id or slug>"
결과가 없음404 + "Outcome not found"
다른 시장의 결과400 + "Outcome does not belong to this market"
Rate limit429 + "ThrottlerException: Too Many Requests" (error 필드 없음)

#Rate limit

공개 엔드포인트는 IP 별로 레이트 리밋이 적용됩니다. 현재 수치는 요청 제한 을 참고하세요.

429 를 받으면 short backoff (수 초) 후 재시도하세요. 지속적으로 막힌다면 Retry-After 헤더를 참고합니다.

#다음

이 페이지가 도움이 되었나요?