Opened 8 years ago

Closed 8 years ago

#26435 closed Cleanup/optimization (wontfix)

GeoIP2 return raw exception from geoip2 package

Reported by: Maxim Filipenko Owned by: nobody
Component: GIS Version: 1.9
Severity: Normal Keywords: geoip2, GeoIP2Exception
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Hi!

When using django.contrib.gis.geoip2 I have to deal with exceptions from django.contrib.gis.geoip2 itself and also from underlying package geoip2. And because of that, for error handling I should include two imports in my source file:

...
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
from geoip2.errors import AddressNotFoundError
...
g = GeoIP2()
try:
    res = g.city(some_ip)
except (AddressNotFoundError, GeoIP2Exception) as e:
   # do something
   pass

It breaks abstraction, because I want to deal only with errors from my gis-component, I don't want to know what exactly underlying package and which errors it can throw.

Maybe GeoIP2Exception should be expanded and thereby django.contrib.gis.geoip2 will not throw underlying package exceptions, because I consider the AddressNotFoundError exception as very basic scenario and it's absolutely should be handled in my code.

Thanks!

Change History (1)

comment:1 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

I think GeoIP2Exception should be raised only if GeoIP2 isn't configured correctly. Therefore I don't think expanding it to subclass more specific runtime exceptions is a good idea. If you have a concrete proposal, feel free to share it.

Note: See TracTickets for help on using tickets.
Back to Top