title: How to modify error response in ModelViewSet class if detail not found for Django REST Framework?
body: <p>I tried to implement this <a href="https://stackoverflow.com/a/47324306/5752558">answer</a> to create a custom base <code>Response</code> class for all my <code>ModelViewSet</code> classes. My problem is at the <code>retrieve</code> function. If the <code>Id</code> of instance I'm looking for not found, I can't seem to change the <code>Response</code> with my modified <code>response_format</code>. It still gives the default response. What should I change my <code>if</code> condition into?<br>
  <code>views.py</code>:  </p>
  
  <pre><code>class ResponseInfo(object):
      def __init__(self, **args):
          self.response = {
              "message": args.get('message', 'success'),
              "error": args.get('error', ),
              "data": args.get('data', []),
          }
  
  
  class LanguageView(viewsets.ModelViewSet):
      def __init__(self, **kwargs):
          self.response_format = ResponseInfo().response
          super(LanguageView, self).__init__(**kwargs)
  
      permission_classes = [permissions.DjangoModelPermissions]
      queryset = Language.objects.all()
      serializer_class = LanguageSerializer
  
      def list(self, request, *args, **kwargs):
          # call the original 'list' to get the original response.
          response_data = super(LanguageView, self).list(request, *args, **kwargs)
          # customize the response data.
          self.response_format['data'] = response_data.data
          if not response_data.data:
              self.response_format['message'] = 'List is empty.'
              self.response_format['error'] = response_data.status_code
          return Response(self.response_format)
  
      def retrieve(self, request, *args, **kwargs):
          response_data = super(LanguageView, self).retrieve(request, *args, **kwargs)
          self.response_format['data'] = response_data.data
          if not response_data.data:
              self.response_format['message'] = 'Instance not found.'
              self.response_format['error'] = response_data.status_code
          return Response(self.response_format)
  </code></pre>
  
  <p>The JSON response when instance is found. E.g <a href="http://127.0.0.1:8000/languages/1/" rel="nofollow noreferrer">http://127.0.0.1:8000/languages/1/</a>:  </p>
  
  <pre><code>{
      "message": "success",
      "error": null,
      "data": {
          "id": 1,
          "name": "English",
          "icon": "http://127.0.0.1:8000/media/language_icons/English.png",
          "xml": "http://127.0.0.1:8000/media/-",
          "abbreviation": "En"
      }
  }
  </code></pre>
  
  <p>The JSON response when instance is not found. E.g URL: <a href="http://127.0.0.1:8000/languages/4/" rel="nofollow noreferrer">http://127.0.0.1:8000/languages/4/</a>:  </p>
  
  <pre><code>{
      "detail": "Not found."
  }
  </code></pre>
  
  <p>The response I'm hoping for:  </p>
  
  <pre><code>{  
      "message": "Instance not found.",  
      "error": "HTTP_404_NOT_FOUND",  
  }
  </code></pre>
  
  <p>And is it possible to not show the <code>"error"</code> variable when there's no error? For this case when list is not empty and the searched instance is found.</p>