2014-02-27 3 views
6

예외 처리를 위해 Cloud Endpoints documentation에서 endpoints.ServiceException 클래스를 서브 클래스 화하여 409 충돌 오류에 대해 사용자 정의 http_status을 제공하는 것이 좋습니다. 다른 질문에 대한 answer은 지원되는 상태 코드 중 일부가 Google 인프라에서 다른 상태 코드로 매핑되지만 409는 매핑 된 상태 코드 중 하나가 아니라는 것을 나타냅니다. 문서에서 ConflictException 클래스를 사용endpoints.ServiceException 하위 클래스가 409 대신 400 상태 코드를 반환합니다.

는 :

import endpoints 
import httplib 

class ConflictException(endpoints.ServiceException): 
    """Conflict exception that is mapped to a 409 response.""" 
    http_status = httplib.CONFLICT 

나는 올릴 때 ConflictException :

@endpoints.method(request_message=apimodels.ClientMessage, 
        response_message=apimodels.ClientMessage, 
        name='insert', 
        path='/clients', 
        http_method='POST' 
) 
def insert(self, request): 
    client = models.Client.get_by_id(request.client_code) 
    if client: 
     raise ConflictException('Entity with the id "%s" exists.' % request.client_code) 

    ... 

내가 응답으로 400 잘못된 요청 받고 있어요 :

400 Bad Request 

Content-Length: 220 
Content-Type: application/json 
Date: Thu, 27 Feb 2014 16:11:36 GMT 
Server: Development/2.0 

{ 
"error": { 
    "code": 400, 
    "errors": [ 
    { 
    "domain": "global", 
    "message": "Entity with the id \"FOO\" exists.", 
    "reason": "badRequest" 
    } 
    ], 
    "message": "Entity with the id \"FOO\" exists." 
} 
} 

로컬의 dev_appserver와 로컬의 양쪽 모두에서 동일한 400 응답 코드가 표시됩니다. App Engine에 배포 (1.9.0) App Engine ProtoRPC 코드를 실행하면 다음 line이 모두 remote.ApplicationError 유형을 400 상태 코드로 매핑하는 것으로 보입니다.

내 사용자 정의 ConflictException 클래스를 추가 할 endpoints.apiserving._ERROR_NAME_MAP DICT를 업데이트하는 경우

, 나는 409 성공적으로 반환 할 수 있어요 :

import endpoints 
import httplib 
from endpoints.apiserving import _ERROR_NAME_MAP 

class ConflictException(endpoints.ServiceException): 
    """Conflict exception that is mapped to a 409 response.""" 
    http_status = httplib.CONFLICT 


_ERROR_NAME_MAP[httplib.responses[ConflictException.http_status]] = ConflictException 

endpoints.ServiceException 서브 클래스를 구현하는 올바른 방법이 있나요?

+0

내 질문에 답을했지만, 같은 질문을 게시했습니다. http://stackoverflow.com/q/26318221/635125. 내가 신선하고 대답을 얻을 수도 있기 때문에 열어 두어야합니까? 더 나은 아직, 브라이언, 당신은 버그 리포트를 제출 했습니까? –

+1

다음 버그를 신고했습니다. https://code.google.com/p/googleappengine/issues/detail?id=11371 –

답변

관련 문제