tastypie not returning NotFound exception error message

Bug #1193022 reported by Brian Murray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Errors
New
Medium
Unassigned

Bug Description

If one uses the package-version-new-buckets resource there is a special NotFound error message which should be raised (I believe). The code for raising that follows:

        previous_version = request.GET.get('previous_version', None)
        new_version = request.GET.get('new_version', None)
        if not launchpad.is_valid_source_version(src_package, previous_version):
            raise NotFound('%s version %s was not found in Launchpad.' % (src_package,
                previous_version))
        if not launchpad.is_valid_source_version(src_package, new_version):
            raise NotFound('%s version %s was not found in Launchpad.' % (src_package,
                new_version))

However, if you provide an invalid package version like in the following url the json content does not include the version not found in Launchpad message. However, you do receive a 404 response.

 $ curl -v https://errors.ubuntu.com/api/1.0/package-version-new-buckets/\?format\=json\&package\=xdiagnose\&previous_version\=3.2.2\&new_version\=0.1.1

< HTTP/1.1 404 NOT FOUND
< Date: Thu, 20 Jun 2013 15:12:03 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Vary: Cookie
< X-Daisy-Revision-Number: 370
< X-Errors-Revision-Number: 438
< Content-Length: 92
< Content-Type: application/json; charset=utf-8
< Strict-Transport-Security: max-age=2592000
<
{
  "error_message": "Sorry, this request could not be processed. Please try again later."
* Connection #0 to host errors.ubuntu.com left intact
}%

summary: - tastypie not returning NotFound excpetion error message
+ tastypie not returning NotFound exception error message
Revision history for this message
Evan (ev) wrote :

It will if you set settings.DEBUG = True, but we don't have that enabled in production. Tastypie does let you override the default error message (settings.TASTYPIE_CANNED_ERROR), but that's global.

I think the cleaner solution would be to override _handle_500 and checking to see if `exception` is an instance of NOT_FOUND_EXCEPTIONS (see tastypie/resources.py:277). If it isn't, call the parent _handle_500. If it is, return self.error_response(request, {'error_message': 'your error goes here'}, response_class=HttpResponseNotFound).

Changed in errors:
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.