ciyidogan commited on
Commit
e43b170
·
verified ·
1 Parent(s): d263994

Update static/js/common.js

Browse files
Files changed (1) hide show
  1. static/js/common.js +7 -1
static/js/common.js CHANGED
@@ -5,9 +5,15 @@ function apiPost(path, body) {
5
  method: 'POST',
6
  headers: { 'Content-Type': 'application/json' },
7
  body: JSON.stringify(body)
8
- }).then(res => res.json());
 
 
 
 
 
9
  }
10
 
 
11
  function apiGet(path) {
12
  return fetch(`${apiBase}${path}`)
13
  .then(res => res.json());
 
5
  method: 'POST',
6
  headers: { 'Content-Type': 'application/json' },
7
  body: JSON.stringify(body)
8
+ }).then(res => {
9
+ if (!res.ok) {
10
+ return res.json().then(err => { throw err; });
11
+ }
12
+ return res.json();
13
+ });
14
  }
15
 
16
+
17
  function apiGet(path) {
18
  return fetch(`${apiBase}${path}`)
19
  .then(res => res.json());