Hide all non-TaskError exceptions from users

This commit is contained in:
rubenwardy 2018-05-14 01:20:02 +01:00
parent 73fa5d1186
commit e6a3836aab
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
5 changed files with 20 additions and 12 deletions

View File

@ -32,6 +32,8 @@ function pollTask(poll_url, disableTimeout) {
if (res.status == "SUCCESS") {
console.log("Got result")
resolve(res.result)
} else if (res.status == "FAILURE" || res.status == "REVOKED") {
reject()
} else {
retry()
}

View File

@ -4,6 +4,12 @@ from celery import Celery
from app import app
from app.models import *
class TaskError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr("TaskError: " + self.value)
class FlaskCelery(Celery):
def __init__(self, *args, **kwargs):
super(FlaskCelery, self).__init__(*args, **kwargs)

View File

@ -4,14 +4,7 @@ import urllib.request
from urllib.parse import urlparse, quote_plus
from app import app
from app.models import *
from app.tasks import celery
class TaskError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
from app.tasks import celery, TaskError
class GithubURLMaker:
def __init__(self, url):
@ -177,6 +170,7 @@ def getMeta(urlstr, author):
@celery.task()
def makeVCSRelease(id, branch):
release = PackageRelease.query.get(id)
if release is None:
raise TaskError("No such release!")

View File

@ -5,10 +5,10 @@ Working
{% endblock %}
{% block content %}
{% if "error" in info %}
{% if "error" in info or info.status == "FAILURE" or info.status == "REVOKED" %}
<h1>Task Failed</h1>
<p>{{ info. error }}</p>
<pre>{{ info.error }}</pre>
{% else %}
<h1>Working…</h1>

View File

@ -3,7 +3,7 @@ from flask_user import *
from flask.ext import menu
from app import app, csrf
from app.models import *
from app.tasks import celery
from app.tasks import celery, TaskError
from app.tasks.importtasks import getMeta
from .utils import shouldReturnJson
# from celery.result import AsyncResult
@ -33,8 +33,14 @@ def check_task(id):
info = {
'id': id,
'status': status,
'error': str(result),
}
if current_user.is_authenticated and current_user.rank.atLeast(UserRank.ADMIN):
info["error"] = str(traceback)
elif str(result)[1:12] == "TaskError: ":
info["error"] = str(result)[12:-1]
else:
info["error"] = "Unknown server error"
else:
info = {
'id': id,