Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on version 1.4.2 - Promise not defined #7

Open
daorithos opened this issue Dec 2, 2015 · 11 comments
Open

Error on version 1.4.2 - Promise not defined #7

daorithos opened this issue Dec 2, 2015 · 11 comments
Labels

Comments

@daorithos
Copy link

Hi, have installed them from gitTio, and when i make a call this is the response:

[ERROR] :  TiExceptionHandler: (main) [56138,56838] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,56838] - In ts.httprequest.js:1,69
[ERROR] :  TiExceptionHandler: (main) [0,56838] - Message: Uncaught ReferenceError: Promise is not defined
[ERROR] :  TiExceptionHandler: (main) [0,56838] - Source: s"!==r&&(this.url=a+("/"!==this.url.charAt(0)?"/":"")+this.url),new Promise(fu
[ERROR] :  V8Exception: Exception occurred at ts.httprequest.js:1: Uncaught ReferenceError: Promise is not defined
@PierreGUI
Copy link
Contributor

Hey,
Maybe gittio was downloading the old (broken, my bad) 1.4.2 release which I just updated.
You can try https://github.com/TheSmiths-Widgets/ts.httprequest/releases/tag/1.4.2 or use NPM instead.

Keep me posted. Cheers

@daorithos
Copy link
Author

Hi :)
when i try from gittio install ts.httprequest or gittio install ts.httprequest@1.4.2 the response is:

[ERROR] Invalid or unsupported zip format. No END header found

if i install from github zip all is ok 👍

@daorithos
Copy link
Author

but it is normal that when I require the module

Alloy.Globals.HttpRequest = require('ts.httprequest');

have this error

[ERROR] :  TiHTTPClient: (TiHttpClient-9) [263,263] HTTP Error (java.io.IOException): 404 : Not Found
[ERROR] :  TiHTTPClient: java.io.IOException: 404 : Not Found
[ERROR] :  TiHTTPClient:    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1216)
[ERROR] :  TiHTTPClient:    at java.lang.Thread.run(Thread.java:818)

@PierreGUI
Copy link
Contributor

Can you paste your code ?

@daorithos
Copy link
Author

sure but i cant show all my file content, i post to you a summary of my code
alloy.js

Alloy.Globals.WSUrl = "http://my/jsonrest";
Alloy.Globals.animations = require('alloy/animation');
Alloy.Globals.HttpRequest = require('ts.httprequest');

Alloy.Globals.myFunc(){}
Alloy.Globals.myFunc(){}
Alloy.Globals.myFunc(){}

app/controllers/Login.js

var args = arguments[0] || {};
var animation = Alloy.Globals.animations;
function loginHandler(){
    var username = $.usernameField.value;
    var password = $.passwordField.value;
        errors = checkErrors();
    if (!errors.length) {
        var request = new Alloy.Globals.HttpRequest({
            method : 'POST',
            url : Alloy.Globals.WSUrl,
            data : {
                method : 'login',
                username : username,
                password : password,
            },
        }).then(function(response) {
            onSuccess();
        }).catch(function(error) {
            inError();
        });
    } else {
        inError();
    }
}

onSuccess(){}
inError(){}

app/vievs/login.xml

<Alloy>
    <Window class="mainWin" exitOnClose="true" layout="vertical" title="Login" theme="Theme.NoActionBar" >
        <ActionBar id="actionbar" />
        <ScrollView id="mainContainer">
            <View id="logosContainer">
                <ImageView image="/images/login/logobg.png" class="toFill" />
                <ImageView id="logoImg" class="logosImages" image="/images/app/logo.png" />
            </View>
            <View id="loginContainer"  height="Ti.UI.SIZE">
                <View id="usernameFieldContainer" class="fieldContainer">
                    <TextField id="usernameField" class="normaltext" keyboardType="Titanium.UI.KEYBOARD_EMAIL" ></TextField>
                    <Label id="usernameLabel" class="inputLabel smalltext bold accentGreen" autoStyle="true">E-mail</Label>
                </View>
                <View id="passwordfieldContainer" class="fieldContainer">
                    <TextField id="passwordField" class="normaltext" passwordMask="true" onReturn="loginHandler"></TextField>
                    <Label id="passwordLabel" class="inputLabel smalltext bold accentGreen" autoStyle="true">Password</Label>
                </View>
                <Button id="loginBtn" class="normaltext accentBgGreen" onClick="loginHandler" autoStyle="true">Login</Button>
            </View>
        </ScrollView>
    </Window>
</Alloy>

when i run che app, in the opening, before run loginHandler(), i see the error in console.

@PierreGUI
Copy link
Contributor

I'm sorry, I can't reproduce the issue.
Android 4.4.4 (API 19)
Titanium 5.0.2.GA

@daorithos
Copy link
Author

mhhh i don't know why... but the is not a big problem.
Thanks for support... and i have another question...

var request = new Alloy.Globals.HttpRequest({
            method : 'POST',
            url : Alloy.Globals.WSUrl,
            data : {
                method : 'login',
                username : username,
                password : password,
            },
        }).then(function(response) {

        }).catch(function(error) {

        });

catch function catch every exception in then but how i can log the exception message? if i log error have empty object.

@KtorZ
Copy link
Contributor

KtorZ commented Dec 7, 2015

It depends of what you're trying to log and with which method.
Using the Ti.API.[debug|info|warn|error] methods, you won't be able to print an object that does not define a toString() method.
Try something like:

.catch(function (error) {
    Ti.API.info(JSON.stringify(error, null, 2))
})

I invite you to have a look at this documentation as well.

Cheers :)

@KtorZ KtorZ added the question label Dec 7, 2015
@daorithos
Copy link
Author

maybe i don't have explained it well....

}).then(function(response) {
    doAnything(response)
    doAnAction(); // this function generate an exception
}).catch(function(error) {
    console.log(error) // or Ti.API.info
});

the response var is ok, the status of call is 200 but the exception of doAnAction cause the catch() execution... the error var is empty object and don't report the exception message.

@KtorZ
Copy link
Contributor

KtorZ commented Dec 7, 2015

I am sorry but I cannot reproduce...

var httprequest = require('ts.httprequest')

new httprequest({
    url: "http://ktorz.github.io/"
}).then(function () {
    throw("My exception")
}).catch(function (e) {
    Ti.API.info(typeof e)
    Ti.API.info(e)
    Ti.API.info(JSON.stringify(e, null, 2))
})

// string
// My Exception
// "My Exception"

This is working fine :/ Maybe there is an issue with your code ?

@daorithos
Copy link
Author

is my code

    var request = new Alloy.Globals.HttpRequest({
        method : 'POST',
        url : Alloy.Globals.URL,
        data : {
            method : 'download',
            username : Alloy.Globals.username,
            password : Alloy.Globals.password,
            uuid : "123",
            s : "123",
            id : id,
        },
    }).then(function(response) {
        file = library.get(id); // library is collection
        saveFile(file, response);
    }).catch(function(error) {
        console.log('error', error);
    });

function saveFile(fileData, blob) {
    if (Ti.Filesystem.isExternalStoragePresent()) {
        var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, fileData.name); // this cause excepton
    } else {
        var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileData.name);
    }

    file.write(blob);

    if (file.exists) {
        Ti.API.info('[saveFile] Saved: YES!');
    } else {
        Ti.API.info('[saveFile] Saved: NO!');
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants