File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,23 @@ def get_sms_backend(phone_number):
1212 if not backend :
1313
1414 if settings .PHONE_VERIFICATION .get ("BACKEND" , None ):
15- backend_import = settings .PHONE_VERIFICATION ["BACKEND" ]
15+ backend_import_path = settings .PHONE_VERIFICATION ["BACKEND" ]
1616 else :
1717 raise ImproperlyConfigured (
1818 "Please specify BACKEND in PHONE_VERIFICATION within your settings"
1919 )
2020
21- backend_cls = import_string (backend_import )
21+ try :
22+ backend_cls = import_string (backend_import_path )
23+ except ImportError as e :
24+ if not any (provider in backend_import_path .lower () for provider in ['twilio' , 'nexmo' ]):
25+ # Error for custom backends
26+ raise RuntimeError (f"Failed to import the specified backend: { backend_import_path } . Ensure the module is installed and properly configured." ) from e
27+
28+ # Extract the module name (e.g., 'twilio' or 'nexmo') for a more meaningful error message
29+ dependency_name = backend_import_path .split ("." )[- 2 ]
30+
31+ # Raise an error with the correct dependency name
32+ raise RuntimeError (f"{ dependency_name .capitalize ()} backend is not installed. Please install '{ dependency_name } ' to use this provider." ) from e
33+
2234 return backend_cls (** settings .PHONE_VERIFICATION ["OPTIONS" ])
You can’t perform that action at this time.
0 commit comments