mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 08:48:18 -05:00
Plugins: Make it possible to add errors to the error list.
This commit is contained in:
@@ -126,6 +126,18 @@ error_list = dict((
|
||||
errors = Storage([(e, e) for e in error_list.keys()])
|
||||
|
||||
|
||||
def add_error_codes(new_codes):
|
||||
"""Add error codes to the error enumeration.
|
||||
|
||||
It is assumed that the incoming messages are marked for translation but not
|
||||
yet translated, so they can be declared before pylons.i18n is ready.
|
||||
|
||||
"""
|
||||
for code, message in new_codes.iteritems():
|
||||
error_list[code] = _(message)
|
||||
errors[code] = code
|
||||
|
||||
|
||||
class RedditError(Exception):
|
||||
name = None
|
||||
fields = None
|
||||
|
||||
@@ -33,6 +33,7 @@ class Plugin(object):
|
||||
config = {}
|
||||
live_config = {}
|
||||
needs_static_build = False
|
||||
errors = {}
|
||||
|
||||
def __init__(self, entry_point):
|
||||
self.entry_point = entry_point
|
||||
@@ -145,5 +146,10 @@ class PluginLoader(object):
|
||||
plugin.on_load(g)
|
||||
|
||||
def load_controllers(self):
|
||||
# this module relies on pylons.i18n._ at import time (for translating
|
||||
# messages) which isn't available 'til we're in request context.
|
||||
from r2.lib import errors
|
||||
|
||||
for plugin in self:
|
||||
errors.add_error_codes(plugin.errors)
|
||||
plugin.load_controllers()
|
||||
|
||||
Reference in New Issue
Block a user