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
Yaxel Perez
jio
Commits
90cdc014
Commit
90cdc014
authored
Oct 24, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command resolver and reject behavior improved
parent
d6e203b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
34 deletions
+71
-34
src/jio/core/restCommandRejecter.js
src/jio/core/restCommandRejecter.js
+39
-17
src/jio/core/restCommandResolver.js
src/jio/core/restCommandResolver.js
+32
-17
No files found.
src/jio/core/restCommandRejecter.js
View file @
90cdc014
...
@@ -6,25 +6,14 @@ function restCommandRejecter(param, args) {
...
@@ -6,25 +6,14 @@ function restCommandRejecter(param, args) {
// reject(status, reason, {..});
// reject(status, reason, {..});
// reject(status, {..});
// reject(status, {..});
var
a
=
args
[
0
],
b
=
args
[
1
],
c
=
args
[
2
],
d
=
args
[
3
],
weak
,
strong
;
var
a
=
args
[
0
],
b
=
args
[
1
],
c
=
args
[
2
],
d
=
args
[
3
],
weak
,
strong
;
weak
=
{
"
result
"
:
"
error
"
};
weak
=
{};
strong
=
{};
strong
=
{
"
result
"
:
"
error
"
};
weak
.
status
=
constants
.
http_status
.
unknown
;
weak
.
statusText
=
constants
.
http_status_text
.
unknown
;
weak
.
message
=
'
Command failed
'
;
weak
.
reason
=
'
fail
'
;
weak
.
method
=
param
.
method
;
if
(
param
.
kwargs
.
_id
)
{
weak
.
id
=
param
.
kwargs
.
_id
;
}
if
(
/Attachment$/
.
test
(
param
.
method
))
{
weak
.
attachment
=
param
.
kwargs
.
_attachment
;
}
// parsing first parameter if is not an object
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
return
restCommandRejecter
(
param
,
[
// can create infernal loop if 'internal_storage_error' is not defined
// can create infernal loop if 'internal_storage_error' is not defined
// in the constants
// in the constants
...
@@ -38,23 +27,56 @@ function restCommandRejecter(param, args) {
...
@@ -38,23 +27,56 @@ function restCommandRejecter(param, args) {
c
=
d
;
c
=
d
;
}
}
// parsing second parameter if is not an object
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
reason
=
a
;
strong
.
reason
=
a
;
a
=
b
;
a
=
b
;
b
=
c
;
b
=
c
;
}
}
// parsing third parameter if is not an object
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
message
=
a
;
strong
.
message
=
a
;
a
=
b
;
a
=
b
;
}
}
// parsing fourth parameter if is an object
if
(
typeof
a
===
'
object
'
&&
!
Array
.
isArray
(
a
))
{
if
(
typeof
a
===
'
object
'
&&
!
Array
.
isArray
(
a
))
{
dictUpdate
(
weak
,
a
);
dictUpdate
(
weak
,
a
);
if
(
typeof
a
.
reason
===
'
string
'
&&
!
strong
.
reason
)
{
strong
.
reason
=
a
.
reason
;
}
if
(
typeof
a
.
message
===
'
string
'
&&
!
strong
.
message
)
{
strong
.
message
=
a
.
message
;
}
if
((
a
.
statusText
||
a
.
status
>=
0
)
&&
!
strong
.
statusText
)
{
strong
.
status
=
constants
.
http_status
[
a
.
statusText
||
a
.
status
];
strong
.
statusText
=
constants
.
http_status_text
[
a
.
statusText
||
a
.
status
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
(
a
.
statusText
||
a
.
status
)
+
'
"
'
]);
}
}
if
(
a
instanceof
Error
)
{
if
(
a
instanceof
Error
)
{
weak
.
reason
=
a
.
message
;
strong
.
reason
=
a
.
message
;
weak
.
error
=
a
.
name
;
strong
.
error
=
a
.
name
;
}
}
}
// creating defaults
weak
.
status
=
constants
.
http_status
.
unknown
;
weak
.
statusText
=
constants
.
http_status_text
.
unknown
;
weak
.
message
=
'
Command failed
'
;
weak
.
reason
=
'
fail
'
;
weak
.
method
=
param
.
method
;
if
(
param
.
kwargs
.
_id
)
{
weak
.
id
=
param
.
kwargs
.
_id
;
}
if
(
/Attachment$/
.
test
(
param
.
method
))
{
weak
.
attachment
=
param
.
kwargs
.
_attachment
;
}
}
dictUpdate
(
weak
,
strong
);
dictUpdate
(
weak
,
strong
);
...
...
src/jio/core/restCommandResolver.js
View file @
90cdc014
...
@@ -6,7 +6,38 @@ function restCommandResolver(param, args) {
...
@@ -6,7 +6,38 @@ function restCommandResolver(param, args) {
// resolve('ok', {"custom": "value"});
// resolve('ok', {"custom": "value"});
// resolve(200, {...});
// resolve(200, {...});
// resolve({...});
// resolve({...});
var
a
=
args
[
0
],
b
=
args
[
1
],
weak
=
{
"
result
"
:
"
success
"
},
strong
=
{};
var
a
=
args
[
0
],
b
=
args
[
1
],
weak
=
{},
strong
=
{
"
result
"
:
"
success
"
};
// parsing first parameter if is a number or a string
if
(
typeof
a
===
'
string
'
||
(
typeof
a
===
'
number
'
&&
isFinite
(
a
)))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
a
+
'
"
'
]);
}
a
=
b
;
}
// parsing second parameter if is an object
if
(
typeof
a
===
'
object
'
&&
a
!==
null
&&
!
Array
.
isArray
(
a
))
{
dictUpdate
(
weak
,
a
);
if
((
a
.
statusText
||
a
.
status
>=
0
)
&&
!
strong
.
statusText
)
{
strong
.
status
=
constants
.
http_status
[
a
.
statusText
||
a
.
status
];
strong
.
statusText
=
constants
.
http_status_text
[
a
.
statusText
||
a
.
status
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
(
a
.
statusText
||
a
.
status
)
+
'
"
'
]);
}
}
}
// creating defaults
if
(
param
.
method
===
'
post
'
)
{
if
(
param
.
method
===
'
post
'
)
{
weak
.
status
=
constants
.
http_status
.
created
;
weak
.
status
=
constants
.
http_status
.
created
;
weak
.
statusText
=
constants
.
http_status_text
.
created
;
weak
.
statusText
=
constants
.
http_status_text
.
created
;
...
@@ -26,22 +57,6 @@ function restCommandResolver(param, args) {
...
@@ -26,22 +57,6 @@ function restCommandResolver(param, args) {
}
}
weak
.
method
=
param
.
method
;
weak
.
method
=
param
.
method
;
if
(
typeof
a
===
'
string
'
||
(
typeof
a
===
'
number
'
&&
isFinite
(
a
)))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
a
+
'
"
'
]);
}
a
=
b
;
}
if
(
typeof
a
===
'
object
'
&&
!
Array
.
isArray
(
a
))
{
dictUpdate
(
weak
,
a
);
}
dictUpdate
(
weak
,
strong
);
dictUpdate
(
weak
,
strong
);
strong
=
undefined
;
// free memory
strong
=
undefined
;
// free memory
if
(
param
.
method
===
'
post
'
&&
(
typeof
weak
.
id
!==
'
string
'
||
!
weak
.
id
))
{
if
(
param
.
method
===
'
post
'
&&
(
typeof
weak
.
id
!==
'
string
'
||
!
weak
.
id
))
{
...
...
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