@sjcrh/proteinpaint-shared 2.170.1 → 2.170.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-shared",
3
- "version": "2.170.1",
3
+ "version": "2.170.3",
4
4
  "description": "ProteinPaint code that is shared between server and client-side workspaces",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -62,10 +62,18 @@ also the caller should just call dofetch2() without a serverData{}
62
62
  rather than dofetch3
63
63
  */
64
64
  export async function processResponse(r) {
65
+ // if (!r.ok) {
66
+ // throw new Error(`HTTP error! status: ${r.status}`)
67
+ // }
65
68
  const ct = r.headers.get('content-type') // content type is always present
66
69
  if (!ct) throw `missing response.header['content-type']`
67
70
  if (ct.includes('/json')) {
68
- return r.json()
71
+ const payload = await r.json()
72
+ // server should use a standard HTTP response status 400+, 500+
73
+ // so that !r.ok will already be caught when wrapping fetch with try-catch
74
+ // if (payload.error || payload.status == '') throw payload
75
+ // if (payload.status === 'error') throw payload.message || payload
76
+ return payload
69
77
  }
70
78
  if (ct.includes('/text') || ct.includes('text/')) {
71
79
  return r.text()
@@ -267,6 +267,7 @@ export function get_bin_label(bin, binconfig, valueConversion) {
267
267
  /*
268
268
  Generate a numeric bin label given a bin configuration and an optional term valueConversion object
269
269
  */
270
+ if (!bin) return 'missing bin.label'
270
271
  if (bin.label) return bin.label
271
272
 
272
273
  const bc = binconfig
@@ -6,6 +6,8 @@ Initialize a bin configuration for a numeric dataset
6
6
  {format: 'string'}: output bin config as JSON string
7
7
  */
8
8
  export default function initBinConfig(data, opts = {}) {
9
+ if (!data.length)
10
+ return { mode: 'discrete', type: 'regular-bin', startinclusive: true, bin_size: null, first_bin: { stop: null } }
9
11
  if (data.find(d => !Number.isFinite(d))) throw new Error('non-numeric values found')
10
12
 
11
13
  let binConfig