Skip to content

How to return a costume error message in graphene? #1147

Description

@aliscie

I created the following class to update the post in spesfic conditions but if the contitions ==False the I need to return {"message": "Only the owner of the post and the admin(website's wonr) can edit and delet this post"} But the JsonResponse don't work likt it is with RestFramework!


class UpdatePost(graphene.Mutation):
      # owner(added_by)+admin can update and delete
      class Arguments:
            id = graphene.Int(required=True)
            description = graphene.String()
      post = graphene.Field(schema.Posts)
      @classmethod
      def mutate(cls, root, info, id, description):
            post = models.Post.objects.get(id=id)
            if (info.context.user == post.added_by):
                  post.description = description
                  post.save()
                  return CreatePost(post=post)
            else:
                 JsoneResponse({"message": "Only the owner of the post and the admin(website's wonr) can edit and delet this post"})
  
[code source on stackoveflow](https://stackoverflow.com/posts/66624122/edit)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions