Ron Au commited on
Commit
0bae5c5
1 Parent(s): f7bfaff

feat(error): Tweaks to logging and error handling

Browse files
Files changed (3) hide show
  1. app.py +3 -3
  2. static/js/index.js +1 -0
  3. static/js/network.js +9 -0
app.py CHANGED
@@ -101,14 +101,14 @@ def create_task(background_tasks: BackgroundTasks, new_task: NewTask):
101
  tasks[task_id] = {
102
  "task_id": task_id,
103
  "status": "queued",
 
104
  "created_at": created_at,
105
  "started_at": None,
106
  "completed_at": None,
 
 
107
  "initial_place_in_queue": None,
108
  "place_in_queue": None,
109
- "poll_count": 0,
110
- "last_poll": None,
111
- "eta": None,
112
  "prompt": new_task.prompt,
113
  "value": None,
114
  }
 
101
  tasks[task_id] = {
102
  "task_id": task_id,
103
  "status": "queued",
104
+ "eta": None,
105
  "created_at": created_at,
106
  "started_at": None,
107
  "completed_at": None,
108
+ "last_poll": None,
109
+ "poll_count": 0,
110
  "initial_place_in_queue": None,
111
  "place_in_queue": None,
 
 
 
112
  "prompt": new_task.prompt,
113
  "value": None,
114
  }
static/js/index.js CHANGED
@@ -69,6 +69,7 @@ const generate = async () => {
69
  setOutput('card', 'completed');
70
  } catch (err) {
71
  generating = false;
 
72
  console.error(err);
73
  }
74
  };
 
69
  setOutput('card', 'completed');
70
  } catch (err) {
71
  generating = false;
72
+ setOutput('booster', 'failed');
73
  console.error(err);
74
  }
75
  };
static/js/network.js CHANGED
@@ -20,6 +20,11 @@ const createTask = async (prompt) => {
20
  },
21
  body: JSON.stringify({ prompt }),
22
  });
 
 
 
 
 
23
  const task = await taskResponse.json();
24
 
25
  return task;
@@ -28,6 +33,10 @@ const createTask = async (prompt) => {
28
  const pollTask = async (task) => {
29
  const taskResponse = await fetch(pathFor(`task/poll?task_id=${task.task_id}`));
30
 
 
 
 
 
31
  return await taskResponse.json();
32
  };
33
 
 
20
  },
21
  body: JSON.stringify({ prompt }),
22
  });
23
+
24
+ if (!taskResponse.ok || !taskResponse.headers.get('content-type')?.includes('application/json')) {
25
+ throw new Error(await taskResponse.text());
26
+ }
27
+
28
  const task = await taskResponse.json();
29
 
30
  return task;
 
33
  const pollTask = async (task) => {
34
  const taskResponse = await fetch(pathFor(`task/poll?task_id=${task.task_id}`));
35
 
36
+ if (!taskResponse.ok || !taskResponse.headers.get('content-type')?.includes('application/json')) {
37
+ throw new Error(await taskResponse.text());
38
+ }
39
+
40
  return await taskResponse.json();
41
  };
42