Example #1
0
    def handle_exception(self, exc):
        if isinstance(exc, tuple(self.expected_exceptions.keys())):
            drf_exception_class = self.expected_exceptions[exc.__class__]
            drf_exception = drf_exception_class(get_error_message(exc))

            return super().handle_exception(drf_exception)

        return super().handle_exception(exc)
Example #2
0
 def test_get_error_message_with_django_validation_error_with_message_dict(
         self):
     self.assertEqual(
         {
             'foo': ['bar', 'foobar'],
             'Some error': ['error text']
         },
         get_error_message(
             ValidationError({
                 'foo': ['bar', 'foobar'],
                 'Some error': 'error text'
             })))
Example #3
0
 def test_get_error_message_with_standard_default_exception(self):
     self.assertEqual('Some error',
                      get_error_message(Exception('Some error')))
Example #4
0
 def test_get_error_message_with_permission_error(self):
     self.assertEqual('Some error',
                      get_error_message(PermissionError('Some error')))
Example #5
0
 def test_get_error_message_with_value_error(self):
     self.assertEqual('Some error',
                      get_error_message(ValueError('Some error')))
Example #6
0
 def test_get_error_message_with_django_permission_denied(self):
     self.assertEqual('Some error',
                      get_error_message(PermissionDenied('Some error')))
Example #7
0
 def test_get_error_message_with_django_validation_error_with_message_list(
         self):
     self.assertEqual(
         'Some error 1, Some error 2',
         get_error_message(ValidationError(['Some error 1',
                                            'Some error 2'])))
Example #8
0
 def test_get_error_message_with_django_validation_error_none(self):
     self.assertEqual('[\'None\']',
                      get_error_message(ValidationError(None)))
Example #9
0
 def test_get_error_message_with_django_validation_error(self):
     self.assertEqual('Some error',
                      get_error_message(ValidationError('Some error')))