0

I trying to log my native-angular applications log in influxdb which is installed on my server. whlie posting log to server API is succeeding and return 204 status code along with the error. for this i have refer many answers like this but not working me .

error:

{
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 204,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure during parsing for (unknown url)",
JS:   "error": {}
JS: }

API Call :

const req = `spl.hpft AppComponent="testing",Message=" ${error.message ? error.message : null}",Error="${error.toString()}"`;
 const headers = new HttpHeaders().set('Content-Transfer-Encoding', 'binary');
 console.log('influxdb request sent');
  this.httpClient.post(InfluxDb_Log, req, {headers:headers,responseType:'text' }).subscribe(payloadResponse => {
  console.log('payloadResponse', payloadResponse);
  console.log('influxdb response received', payloadResponse);
}, error => {
  console.log('influx error', error);
}); 
Sarjerao Ghadage
  • 1,420
  • 16
  • 31
  • what is the value of InfluxDb_Log , is it working when you do a post call via postman tool ? – Senthil Jun 05 '19 at 09:45
  • http://182.157.203.148:6060/write?db=dbname – Sarjerao Ghadage Jun 05 '19 at 09:56
  • yes its working via postman – Sarjerao Ghadage Jun 05 '19 at 09:58
  • show / comment your request and response which you received while using postman – Senthil Jun 05 '19 at 10:14
  • request : dbname.test AppComponent="testing",Message=" this is test error",Error="Error: this is test error" – Sarjerao Ghadage Jun 05 '19 at 10:16
  • response:status:204 No Content – Sarjerao Ghadage Jun 05 '19 at 10:17
  • so as per your code logic, is it going to error block ? ref: Because of some custom Interceptors also it can go to error response : https://stackoverflow.com/questions/33655651/why-does-a-post-response-of-204-no-content-trigger-the-angularjs-error-functio – Senthil Jun 05 '19 at 10:39
  • no its not going to error back – Sarjerao Ghadage Jun 05 '19 at 10:46
  • Which device and OS version you are testing the app with? On iOS you will have to enable Http (non-secure) requests explicitly, unless all requests will simply fail. Refer [this thread](https://stackoverflow.com/questions/31216758/how-can-i-add-nsapptransportsecurity-to-my-info-plist-file) for detailed answer, the `info.plist` can be found under `/App_Resources/iOS` folder. If you are using Android 9, the same applies, refer [this answer](https://stackoverflow.com/a/53253643/1060423) If you still face issues, please share a Playground Sample where the issue can be reproduced. – Manoj Jun 05 '19 at 13:26
  • tns-android has 5.4.0 & it's running on the device emulator. – Sarjerao Ghadage Jun 06 '19 at 04:58

1 Answers1

1

I think your rest api returning content-type="application/json".nativescript xhr checking the content-type response header.if the content-type ="application/json" then it will parse the data.actually 204 returning empty string , so it will throw error.I think this one should be fix native script team.so u can fix it by remove the content-type header from your response or pass the content-type = "text" , both will support in native script.just try it

yoosuf
  • 29
  • 3