Open daorithos opened 8 years ago
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
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 :+1:
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)
Can you paste your code ?
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.
I'm sorry, I can't reproduce the issue. Android 4.4.4 (API 19) Titanium 5.0.2.GA
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.
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 :)
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.
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 ?
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!');
}
}
Hi, have installed them from gitTio, and when i make a call this is the response: