Mercurial > kallithea
comparison rhodecode/controllers/api/__init__.py @ 1661:fe5575f95850 beta
API returns proper JSON response
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 08 Nov 2011 17:13:46 +0200 |
parents | 87ec80c280bb |
children | 60249224be04 |
comparison
equal
deleted
inserted
replaced
1660:5568b0cea3cc | 1661:fe5575f95850 |
---|---|
34 from rhodecode.lib.compat import izip_longest, json | 34 from rhodecode.lib.compat import izip_longest, json |
35 | 35 |
36 from paste.response import replace_header | 36 from paste.response import replace_header |
37 | 37 |
38 from pylons.controllers import WSGIController | 38 from pylons.controllers import WSGIController |
39 from pylons.controllers.util import Response | 39 |
40 | 40 |
41 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ | 41 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ |
42 HTTPBadRequest, HTTPError | 42 HTTPBadRequest, HTTPError |
43 | 43 |
44 from rhodecode.model.db import User | 44 from rhodecode.model.db import User |
54 def __str__(self): | 54 def __str__(self): |
55 return str(self.message) | 55 return str(self.message) |
56 | 56 |
57 | 57 |
58 def jsonrpc_error(message, code=None): | 58 def jsonrpc_error(message, code=None): |
59 """Generate a Response object with a JSON-RPC error body""" | 59 """ |
60 return Response(body=json.dumps(dict(result=None, | 60 Generate a Response object with a JSON-RPC error body |
61 error=message))) | 61 """ |
62 from pylons.controllers.util import Response | |
63 resp = Response(body=json.dumps(dict(result=None, error=message)), | |
64 status=code, | |
65 content_type='application/json') | |
66 return resp | |
67 | |
62 | 68 |
63 | 69 |
64 class JSONRPCController(WSGIController): | 70 class JSONRPCController(WSGIController): |
65 """ | 71 """ |
66 A WSGI-speaking JSON-RPC controller class | 72 A WSGI-speaking JSON-RPC controller class |