Description
Background:
After we upgraded our app to NativeScript 3.2 and nativescript-angular 4.2 we've ran into the following issue #949.
To solve this we've upgraded nativescript-angular to 4.4.1 and angular to 4.4.5.
But with this version we are no longer able to retrieve html files from the local file system. The content is properly loaded but returned in the error handler of the stream.
You can use the following example to recreate the issue:
https://github.com/corne-de-bruin/retrieve-local-html-example
Just clone the project and run:
npm i
tns prepare android
tns run android
In the console you will see that it end's up in the error handler of the request.
If I'm right it's related to the following function in "nativescript-angular/http-client/http-utils.ts"
return new Observable((observer: Observer<T>) => {
if (nsFileSystem.fileExists(url)) {
const localFile = nsFileSystem.fileFromPath(url);
localFile.readText()
.then((data) => {
try {
const json = JSON.parse(data);
observer.next(successResponse(url, json, 200));
observer.complete();
} catch (error) {
// Even though the response status was 2xx, this is still an error.
// The parse error contains the text of the body that failed to parse.
const errorResult = { error, text: data };
observer.error(errorResponse(url, errorResult, 200));
}
}, (err: Object) => {
observer.error(errorResponse(url, err, 400));
});
} else {
observer.error(errorResponse(url, "Not Found", 404));
}
});
This tries to parse all local loaded files to JSON.