Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
9a18dfde
Commit
9a18dfde
authored
Dec 13, 2017
by
Alain Takoudjou
Committed by
Romain Courteaud
Jan 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jio ajax: allow to set a request timeout value
parent
c915f90b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
src/jio.js
src/jio.js
+7
-0
test/jio/util.js
test/jio/util.js
+49
-2
No files found.
src/jio.js
View file @
9a18dfde
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} param.url The url
* @param {String} param.url The url
* @param {Any} [param.data] The data to send
* @param {Any} [param.data] The data to send
* @param {Number} param.timeout The request timeout value
* @param {Function} [param.beforeSend] A function called just before the
* @param {Function} [param.beforeSend] A function called just before the
* send request. The first parameter of this function is the XHR object.
* send request. The first parameter of this function is the XHR object.
* @return {Promise} The promise
* @return {Promise} The promise
...
@@ -72,6 +73,12 @@
...
@@ -72,6 +73,12 @@
}
}
}
}
}
}
if
(
param
.
timeout
!==
undefined
&&
param
.
timeout
!==
0
)
{
xhr
.
timeout
=
param
.
timeout
;
xhr
.
ontimeout
=
function
()
{
return
reject
(
new
jIO
.
util
.
jIOError
(
"
Gateway Timeout
"
,
504
));
};
}
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
param
.
beforeSend
(
xhr
);
param
.
beforeSend
(
xhr
);
}
}
...
...
test/jio/util.js
View file @
9a18dfde
(
function
(
jIO
,
QUnit
)
{
/*global setTimeout*/
(
function
(
jIO
,
QUnit
,
setTimeout
)
{
"
use strict
"
;
"
use strict
"
;
var
test
=
QUnit
.
test
,
var
test
=
QUnit
.
test
,
equal
=
QUnit
.
equal
,
equal
=
QUnit
.
equal
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
expect
=
QUnit
.
expect
,
module
=
QUnit
.
module
;
module
=
QUnit
.
module
;
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -29,4 +33,47 @@
...
@@ -29,4 +33,47 @@
});
});
}(
jIO
,
QUnit
));
/////////////////////////////////////////////////////////////////
\ No newline at end of file
// util.ajax
/////////////////////////////////////////////////////////////////
module
(
"
util.ajax
"
,
{
setup
:
function
()
{
var
context
=
this
;
this
.
jioerror
=
jIO
.
util
.
jIOError
;
this
.
error_spy
=
{};
function
fakejIOError
(
message
,
status_code
)
{
context
.
error_spy
.
message
=
message
;
context
.
error_spy
.
status_code
=
status_code
;
}
fakejIOError
.
prototype
=
new
Error
();
fakejIOError
.
prototype
.
constructor
=
fakejIOError
;
jIO
.
util
.
jIOError
=
fakejIOError
;
},
teardown
:
function
()
{
jIO
.
util
.
jIOError
=
this
.
jioerror
;
}
});
test
(
"
ajax timeout
"
,
function
()
{
var
timeout
=
1
,
context
=
this
;
stop
();
expect
(
2
);
jIO
.
util
.
ajax
({
type
:
'
GET
'
,
url
:
"
//www.foo/com/bar
"
,
timeout
:
timeout
});
setTimeout
(
function
()
{
start
();
equal
(
context
.
error_spy
.
message
,
"
Gateway Timeout
"
);
equal
(
context
.
error_spy
.
status_code
,
504
);
},
10
);
});
}(
jIO
,
QUnit
,
setTimeout
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment