mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 08:17:58 -05:00
Generalize strict validation error abort method.
This commit is contained in:
@@ -25,7 +25,7 @@ from pylons.i18n import _
|
||||
|
||||
from r2.config.extensions import set_extension
|
||||
from r2.controllers.api_docs import api_doc, api_section
|
||||
from r2.controllers.reddit_base import RedditController
|
||||
from r2.controllers.reddit_base import RedditController, abort_with_error
|
||||
from r2.controllers.oauth2 import (
|
||||
OAuth2ResourceController,
|
||||
require_oauth2_scope,
|
||||
@@ -56,8 +56,7 @@ from r2.lib.jsontemplates import (
|
||||
LabeledMultiJsonTemplate,
|
||||
LabeledMultiDescriptionJsonTemplate,
|
||||
)
|
||||
from r2.lib.errors import errors, reddit_http_error, RedditError
|
||||
from r2.lib.base import abort
|
||||
from r2.lib.errors import errors, RedditError
|
||||
|
||||
|
||||
multi_sr_data_json_spec = VValidatedJSON.Object({
|
||||
@@ -77,22 +76,13 @@ multi_description_json_spec = VValidatedJSON.Object({
|
||||
|
||||
|
||||
class MultiApiController(RedditController, OAuth2ResourceController):
|
||||
on_validation_error = staticmethod(abort_with_error)
|
||||
|
||||
def pre(self):
|
||||
set_extension(request.environ, "json")
|
||||
self.check_for_bearer_token()
|
||||
RedditController.pre(self)
|
||||
|
||||
def on_validation_error(self, error):
|
||||
if not error.code:
|
||||
raise ValueError('Error %r missing status code' % error)
|
||||
|
||||
abort(reddit_http_error(
|
||||
code=error.code,
|
||||
error_name=error.name,
|
||||
explanation=error.message,
|
||||
fields=error.fields,
|
||||
))
|
||||
|
||||
@require_oauth2_scope("read")
|
||||
@validate(VUser())
|
||||
@api_doc(api_section.multis, uri="/api/multi/mine")
|
||||
|
||||
@@ -54,6 +54,7 @@ from r2.lib.errors import (
|
||||
BadRequestError,
|
||||
ForbiddenError,
|
||||
errors,
|
||||
reddit_http_error,
|
||||
)
|
||||
from r2.lib.filters import _force_utf8
|
||||
from r2.lib.strings import strings
|
||||
@@ -697,6 +698,18 @@ def flatten_response(content):
|
||||
return "".join(_force_utf8(x) for x in tup(content) if x)
|
||||
|
||||
|
||||
def abort_with_error(error):
|
||||
if not error.code:
|
||||
raise ValueError('Error %r missing status code' % error)
|
||||
|
||||
abort(reddit_http_error(
|
||||
code=error.code,
|
||||
error_name=error.name,
|
||||
explanation=error.message,
|
||||
fields=error.fields,
|
||||
))
|
||||
|
||||
|
||||
class MinimalController(BaseController):
|
||||
|
||||
allow_stylesheets = False
|
||||
|
||||
Reference in New Issue
Block a user