Skip to content

Error handling in Query #857

@daudln

Description

@daudln

Currently (in documentation) we have a nice way to handle error, particulary using @strawberry_django.mutation(handle_django_errors=True) or setting Global via settings.py

This feature is good, but It will nice if have the same way in query.

For example, if we apply IsAuthenticated instead of returning an empty data like

{
  "data": {
    "sectors": {
      "pageInfo": {
        "offset": 0,
        "limit": 20
      },
      "totalCount": 0,
      "results": []
    }
  }
}

I think it will be nice return error instead ie

{
  "data": {
    "sectors": {
      "messages": [
        {
          "kind": "PERMISSION",
          "message": "User is not authenticated.",
          "field": "sectors",
          "code": null
        }
      ]
    }
  }
}

That mean, to have an option to supply ie handle_django_exceptions (at least for now), so we have a meaningful message to user about why getting empty data (as shown above)

PoC

  1. Using offset_paginated

sectors: OffsetPaginated[types.SectorType] = offset_paginated(handle_django_exceptions=True, extensions=[IsAuthenticated()])

  1. Using field

@strawberry_django.field(handle_django_exceptions=True, extensions=[IsAuthenticated()]))

Feature Request Type

  • New behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions