Skip to content

Handling invalid UUIDs in URL parameters #3377

@ghost

Description

I have been looking around forums and within the DRF issues but cant seem to find any examples how to handle invalid UUIDs passed in via browser.

My REST end point is as follows using default SimpleRouter

http://localhost/api/v1/customers/3d70aa0089b64e32a358af90c5df57272b7

router = routers.SimpleRouter(trailing_slash=True)
router.register(r'customers', views.CustomerViewSet, 'customer')

If I was to pass in an invalid UUID i would get html response saying

ValueError: badly formed hexadecimal UUID string

Is they any way catch ValueError and return a custom JSON response such as invalid id that can be applied globally as most of my primary keys are UUIDs. Appreciate if anyone can point me to the right direction.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy