سؤال

I would like to create a user defined MessageField like DateTimeField. I have created one as follows:

class ErrorMessage(Message):
    code = StringField(1, required=True)
    message = StringField(2, required=True)
    reference = StringField(3, required=True)

class ErrorField(MessageField):
    message_type = ErrorMessage

    @util.positional(3)
    def __init__(self, number, **kwargs):
        super(ErrorField, self).__init__(self.message_type, number, **kwargs)

Does it sound right? I have used this ErrorField as one of the field in response class of Google cloud endpoints. It works well with JS client but when used with android, error object gets in the format error="".

     return  MyResponse(
        isSaved=False,
        error=ErrorMessage(code="200", message=simplejson.dumps(form.errors), reference="form validation error")
       )

     from protorpc.messages import Message, StringField, MessageField

     class MyResponse(Message):
        isSaved = StringField(1, required=True)
        error = ErrorField(2, required = False)

I need common Error class for my endpoints, for that I need a custom ErrorField. Thanks in advance.

هل كانت مفيدة؟

المحلول

See the Endpoints Exceptions documentation.

For example, to send a 400

raise endpoints.BadRequestException('A bad thing happened.')

Some more helpful answers:
Returning custom HTTP error reasons in Google Cloud Endpoints
How can one subclass endpoints.ServiceException?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top