File tree 1 file changed +14
-2
lines changed
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):
12
12
if not backend :
13
13
14
14
if settings .PHONE_VERIFICATION .get ("BACKEND" , None ):
15
- backend_import = settings .PHONE_VERIFICATION ["BACKEND" ]
15
+ backend_import_path = settings .PHONE_VERIFICATION ["BACKEND" ]
16
16
else :
17
17
raise ImproperlyConfigured (
18
18
"Please specify BACKEND in PHONE_VERIFICATION within your settings"
19
19
)
20
20
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
+
22
34
return backend_cls (** settings .PHONE_VERIFICATION ["OPTIONS" ])
You can’t perform that action at this time.
0 commit comments