appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 468 forks source link

How to validate query or error check response with customQuery #945

Closed danielsnider closed 5 years ago

danielsnider commented 5 years ago

Issue Type: enhancement

Description: I'm using the customQuery feature of my DataSearch component to send String Queries to ElasticSearch. Sometimes the user enters an invalid string query and a 200 is sent back with the error message:

{"responses":[{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [foo(bar]" ...

Returning 200 here seems insane to me, but how can we get ReactiveSearch to deal with this? Currently ReactiveSearch doesn't know what to do and it does nothing, it appears to keep loading (although it is not) until a valid query is entered.

Here's my customQuery definition to enable String Queries syntax.

function customQuery(value, props) {
  return {
    "query": {
        "query_string" : {
            "query" : value
        }
    }
  };
}

The problem is that I can't access the response of my customQuery so I cannot check for the error: {"responses":[{"error":{"root_cause": ... ☹. onData doesn't give this data either and onError doesn't trigger.

Right now my hacky work around plan (that I'm dreading) is in beforeValueChange to setup a my own connection to ElasticSearch (outside of ReactiveSearch😭) and send an XHR to the Validate API request to precheck the query. It's gross!

Any ideas would be a life saver!

danielsnider commented 5 years ago

This ElasticSearch query parameter might be helpful!

allow_partial_search_results | Set to false to return an overall failure if the request would produce partial results. Defaults to true, which will allow partial results in the case of timeouts or partial failures. This default can be controlled using the cluster-level settingsearch.default_allow_partial_results. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html

But there is still a problem. The allow_partial_search_results setting must be passed as query-string parameters which isn't possible using customQuery, right? I've created an ElasticSearch issue to ask for more flexibility than just a query-string parameter.

danielsnider commented 5 years ago

So the solution should be setting this global config setting, but the setting is not working 😟. If you have any suggestion to try to get it to work, it would be much appreciated!

$ curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
    "persistent" : {
        "search.default_allow_partial_results" : "false"
    }
}
'
danielsnider commented 5 years ago

Ignore my last two comments. The option doesn't actually help here (see ElasticSearch issue).

So I reiterate the problem: ElasticSearch is insane and returns a 200 HTTP status when there is a query parsing error and no result data. Currently ReactiveSearch doesn't know what to do and it does nothing, it appears to keep loading (although it is not) until a valid query is entered. How can we get ReactiveSearch to deal with this error inside of 200 responses?

Full search request:

Request URL: http://192.168.136.128:9200/image/_msearch?
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.136.128:9200
Referrer Policy: no-referrer-when-downgrade
accept: application/json
content-type: application/x-ndjson
Origin: http://192.168.136.128:3000
Referer: http://192.168.136.128:3000/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
x-requested-with: 771100

{"preference":"modality-list"}
{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"fields":["*"],"query":"heart("}}]}}]}},"highlight":{"pre_tags":["<mark>"],"post_tags":["</mark>"],"fields":{}},"size":0,"_source":{"includes":["*"],"excludes":[]},"from":0,"aggs":{"Modality.raw":{"terms":{"field":"Modality.raw","size":20,"order":{"_count":"desc"}}}}}
{"preference":"bodypart-list"}
{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"fields":["*"],"query":"heart("}}]}}]}},"highlight":{"pre_tags":["<mark>"],"post_tags":["</mark>"],"fields":{}},"size":0,"_source":{"includes":["*"],"excludes":[]},"from":0,"aggs":{"BodyPartExamined.raw":{"terms":{"field":"BodyPartExamined.raw","size":100,"order":{"_count":"desc"}}}}}
{"preference":"gender-list"}
{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"fields":["*"],"query":"heart("}}]}}]}},"highlight":{"pre_tags":["<mark>"],"post_tags":["</mark>"],"fields":{}},"size":0,"_source":{"includes":["*"],"excludes":[]},"from":0,"aggs":{"PatientSex.raw":{"terms":{"field":"PatientSex.raw","size":20,"order":{"_count":"desc"}}}}}
{"preference":"tagCloud"}
{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"fields":["*"],"query":"heart("}}]}}]}},"highlight":{"pre_tags":["<mark>"],"post_tags":["</mark>"],"fields":{}},"size":0,"_source":{"includes":["*"],"excludes":[]},"from":0,"aggs":{"descriptions.raw":{"terms":{"field":"descriptions.raw","size":200,"order":{"_term":"asc"}}}}}
{"preference":"results"}
{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"fields":["*"],"query":"heart("}}]}}]}},"highlight":{"pre_tags":["<mark>"],"post_tags":["</mark>"],"fields":{}},"size":12,"_source":{"includes":["*"],"excludes":[]},"from":0}

Full HTTP 200 OK response:

access-control-allow-credentials: true
access-control-allow-origin: *
content-encoding: gzip
content-length: 538
content-type: application/json; charset=UTF-8
Warning: 299 Elasticsearch-6.7.1-2f32220 "Deprecated aggregation order key [_term] used, replaced by [_key]"

{"responses":[{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"image","node":"X6uClAg5SimP2fxx3L872g","reason":{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image","caused_by":{"type":"parse_exception","reason":"Cannot parse 'heart(': Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    "}}}}]},"status":400},{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"image","node":"X6uClAg5SimP2fxx3L872g","reason":{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image","caused_by":{"type":"parse_exception","reason":"Cannot parse 'heart(': Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    "}}}}]},"status":400},{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"image","node":"X6uClAg5SimP2fxx3L872g","reason":{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image","caused_by":{"type":"parse_exception","reason":"Cannot parse 'heart(': Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    "}}}}]},"status":400},{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"image","node":"X6uClAg5SimP2fxx3L872g","reason":{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image","caused_by":{"type":"parse_exception","reason":"Cannot parse 'heart(': Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    "}}}}]},"status":400},{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"image","node":"X6uClAg5SimP2fxx3L872g","reason":{"type":"query_shard_exception","reason":"Failed to parse query [heart(]","index_uuid":"FqZfR415QIuajKOY32gXYg","index":"image","caused_by":{"type":"parse_exception","reason":"Cannot parse 'heart(': Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 6.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    "}}}}]},"status":400}]}

Any ideas?

danielsnider commented 5 years ago

I've checked with the ElasticSearch team (issue) and they repetitively say they won't help us with this.

The problem is that I can't access the response of my customQuery so I cannot check for the error: {"responses":[{"error":{"root_cause": ... ☹. onData doesn't give this data either and onError doesn't trigger. Currently ReactiveSearch doesn't know what to do and it does nothing, it appears to keep loading (although it is not) until a valid query is entered. The solution needed is to bubble up an error. Please point me in the right direction to help me write a fix at least!

Many thanks!

bietkul commented 5 years ago

Whenever a query is wrong, elasticsearch throws the 200 with an error response, I think we should handle it in appbase-js and invoke the onError with the error message. @siddharthlatest What do you think?

siddharthlatest commented 5 years ago

@bietkul @danielsnider This seems specific to the _msearch query. I agree with the premise of handling the error in a better way.

@danielsnider If you are interested in fixing this, the fix should most likely be applied over here: https://github.com/appbaseio/appbase-js/blob/develop/src/core/request/fetch.js#L64.

danielsnider commented 5 years ago

Hi @siddharthlatest, we've taken a stab at a fix but we are stuck with an error when building your code into the minified format (which is what I found for appbase-js in my node_modules). I would rather test non-minified code in my node_modules but I tried dropping it in and I got import errors.

Here's the error I got when building your code into minified format:

dan@ubuntu:~/aim/node_modules$ rm -fr appbase-js/
dan@ubuntu:~/aim/node_modules$ git clone https://github.com/appbaseio/appbase-js
dan@ubuntu:~/aim/node_modules$ cd appbase-js/
dan@ubuntu:~/aim/node_modules/appbase-js$ npm install --only=dev

npm WARN deprecated kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated object-keys@0.2.0: Please update to the latest object-keys

> husky@0.14.3 install /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/husky
> node ./bin/install.js

husky
setting up Git hooks
trying to install from sub 'node_module' directory, skipping Git hooks installation

> appbase-js@4.0.2-beta.5 prepare /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js
> npm start validate

> appbase-js@4.0.2-beta.5 start /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js
> nps "validate"

nps is executing `validate` : node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold" --prefix "[{name}]" --names "compileToes5,lint,build.andTest" 'nps compileToes5
' 'nps lint' 'nps build.andTest'
[compileToes5] nps is executing `compileToes5` : node node_modules/rimraf/bin.js lib && babel src/shim -d lib
[lint] nps is executing `lint` : eslint .
[build.andTest] nps is executing `build.andTest` : nps build
[build.andTest] nps is executing `build` : node node_modules/rimraf/bin.js dist && node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold,bgBlack.bold,bgCyan.bold" -
-prefix "[{name}]" --names "compileToes5,build.es,build.cjs,build.umd.main,build.umd.min" 'nps compileToes5' 'nps build.es' 'nps build.cjs' 'nps build.umd.main' 'nps build.umd.min'
[compileToes5] src/shim/ws-shim.js -> lib/ws-shim.js
[compileToes5] nps compileToes5 exited with code 0
[build.andTest] [build.cjs] nps is executing `build.cjs` : rollup --config --environment FORMAT:cjs
[build.andTest] [compileToes5] nps is executing `compileToes5` : node node_modules/rimraf/bin.js lib && babel src/shim -d lib
[build.andTest] [build.es] nps is executing `build.es` : rollup --config --environment FORMAT:es
[build.andTest] [build.umd.main] nps is executing `build.umd.main` : rollup --config --sourcemap --environment FORMAT:umd
[build.andTest] [build.umd.min] nps is executing `build.umd.min` : rollup --config --sourcemap --environment MINIFY,FORMAT:umd
[build.andTest] [compileToes5] src/shim/ws-shim.js -> lib/ws-shim.js
[build.andTest] [build.cjs] 
[build.andTest] [build.cjs] src/index.js → dist/appbase-js.cjs.js...
[build.andTest] [compileToes5] nps compileToes5 exited with code 0
[build.andTest] [build.es] 
[build.andTest] [build.es] src/index.js → dist/appbase-js.es.js...
[build.andTest] [build.umd.main] 
[build.andTest] [build.umd.main] src/index.js → dist/appbase-js.umd.js...
[build.andTest] [build.umd.min] 
[build.andTest] [build.umd.min] src/index.js → dist/appbase-js.umd.min.js...
[lint] 
[lint] /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/src/core/request/ws.js
[lint]    57:13  warning  Unexpected console statement  no-console
[lint]    97:9   warning  Unexpected console statement  no-console
[lint]   147:7   warning  Unexpected console statement  no-console
[lint] 
[lint] /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/src/index.js
[lint]   49:40  warning  Unexpected unnamed function  func-names
[lint] 
[lint] ✖ 4 problems (0 errors, 4 warnings)
[lint] 
[lint] nps lint exited with code 0
[build.andTest] [build.umd.main] [!] (babel plugin) ReferenceError: Unknown plugin "external-helpers" specified in "base" at 1, attempted to resolve relative to "/home/dan/aim-platform/image-archive/reactive-search/node_modules/url-
parser-lite"
[build.andTest] [build.umd.main] ../url-parser-lite/index.js
[build.andTest] [build.umd.main] ReferenceError: Unknown plugin "external-helpers" specified in "base" at 1, attempted to resolve relative to "/home/dan/aim-platform/image-archive/reactive-search/node_modules/url-parser-lite"
[build.andTest] [build.umd.main]     at /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17
[build.andTest] [build.umd.main]     at Array.map (<anonymous>)
[build.andTest] [build.umd.main]     at Function.normalisePlugins (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
[build.andTest] [build.umd.main]     at OptionManager.mergeOptions (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
[build.andTest] [build.umd.main]     at OptionManager.init (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
[build.andTest] [build.umd.main]     at File.initOptions (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/index.js:212:65)
[build.andTest] [build.umd.main]     at new File (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/file/index.js:135:24)
[build.andTest] [build.umd.main]     at Pipeline.transform (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
[build.andTest] [build.umd.main]     at /home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:57:26
[build.andTest] [build.umd.main]     at Object.transform$1 (/home/dan/aim-platform/image-archive/reactive-search/node_modules/appbase-js/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:141:18)
[build.andTest] [build.umd.main] 
[build.andTest] [build.cjs] created dist/appbase-js.cjs.js in 2.1s
[build.andTest] [build.umd.main] The script called "build.umd.main" which runs "rollup --config --sourcemap --environment FORMAT:umd" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md
#failed-with-exit-code
[build.andTest] [build.umd.main] nps build.umd.main exited with code 1
[build.andTest] --> Sending SIGTERM to other processes..
[build.andTest] [build.cjs] nps build.cjs exited with code 0
[build.andTest] [build.umd.min] nps build.umd.min exited with code null
[build.andTest] [build.es] nps build.es exited with code null
[build.andTest] The script called "build" which runs "node node_modules/rimraf/bin.js dist && node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold,bgBlack.bold,bgC
yan.bold" --prefix "[{name}]" --names "compileToes5,build.es,build.cjs,build.umd.main,build.umd.min" 'nps compileToes5' 'nps build.es' 'nps build.cjs' 'nps build.umd.main' 'nps build.umd.min'" failed with exit code 1 https://github.
com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
[build.andTest] The script called "build.andTest" which runs "nps build" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
[build.andTest] nps build.andTest exited with code 1
The script called "validate" which runs "node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold,bgGreen.bold" --prefix "[{name}]" --names "compileToes5,lint,build.andTest" 'nps c
ompileToes5' 'nps lint' 'nps build.andTest'" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.9.5/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appbase-js@4.0.2-beta.5 start: `nps "validate"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the appbase-js@4.0.2-beta.5 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dan/.npm/_logs/2019-05-10T17_57_42_439Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appbase-js@4.0.2-beta.5 prepare: `npm start validate`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the appbase-js@4.0.2-beta.5 prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dan/.npm/_logs/2019-05-10T17_57_42_511Z-debug.log

Please help! I'd be happy if you told me how to fix this error, or told me how to test your code without minifying, or if you release a fix that addresses my issue (by handling the ElasticSearch error in a better way). 😁 Thanks!!

cc: @diannamcallister

bietkul commented 5 years ago

I think you can ignore it for now

danielsnider commented 5 years ago

@bietkul I can't ignore my lack of built files. What you mean ignore?

node_modules/appbase-js$ find dist lib
dist
dist/appbase-js.cjs.js
lib
lib/ws-shim.js
bietkul commented 5 years ago

I'm not sure where you're getting this. Just clone the repo from here and run yarn You can test it by adding a test case and run yarn test If it works than create a PR

danielsnider commented 5 years ago

@bietkul Thanks! Yes, it's as simple as that! No matter how simple, it would be good to say that in your documentation. I had looked on your README for build instructions but there are none. It would have saved us both time 👍.

danielsnider commented 5 years ago

Many thanks for the help ya'll! We got it working.

Here's a quick diff to see how we fixed it. Nothing special, for sure!


index 2186bb8..0f5b45c 100644                                                                                                                        
--- a/src/core/request/fetch.js                                                                                                                      
+++ b/src/core/request/fetch.js                                                                                                                      
@@ -62,6 +62,13 @@ function fetchRequest(args) {                                                                                                     
         `${this.protocol}://${this.url}/${this.app}/${path}?${querystring.stringify(params)}`,                                                      
         finalRequest,                                                                                                                               
       ).then((res) => {                                                                                                                             
+        res.clone().json().then((res2) => {                                                                                                         
+        const allResponses = res2.responses.length;                                                                                                 
+        const errorResponses = res2.responses.filter(entry => entry.hasOwnProperty('error')).length;                                                
+        if (allResponses === errorResponses) {                                                                                                      
+          return reject(res2);                                                                                                                      
+        }                                                                                                                                           
+     });                                                                                                                                            
         if (res.status >= 500) {                                                                                                                    
           return reject(res);                                                                                                                       
         }```