Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hive-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hive-js
Commits
6df505b0
Commit
6df505b0
authored
6 years ago
by
Roger Jungemann
Browse files
Options
Downloads
Patches
Plain Diff
Address PR comments
parent
545c15d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/transports/http.js
+18
-9
18 additions, 9 deletions
src/api/transports/http.js
with
18 additions
and
9 deletions
src/api/transports/http.js
+
18
−
9
View file @
6df505b0
...
@@ -14,9 +14,20 @@ class RPCError extends Error {
...
@@ -14,9 +14,20 @@ class RPCError extends Error {
}
}
}
}
export
function
jsonRpc
(
uri
,
{
method
,
id
,
params
,
fetchMethod
})
{
/**
* Makes a JSON-RPC request using `fetch` or a user-provided `fetchMethod`.
*
* @param {string} uri - The URI to the JSON-RPC endpoint.
* @param {string} options.method - The remote JSON-RPC method to call.
* @param {string} options.id - ID for the request, for matching to a response.
* @param {*} options.params - The params for the remote method.
* @param {function} [options.fetchMethod=fetch] - A function with the same
* signature as `fetch`, which can be used to make the network request, or for
* stubbing in tests.
*/
export
function
jsonRpc
(
uri
,
{
method
,
id
,
params
,
fetchMethod
=
fetch
})
{
const
payload
=
{
id
,
jsonrpc
:
'
2.0
'
,
method
,
params
};
const
payload
=
{
id
,
jsonrpc
:
'
2.0
'
,
method
,
params
};
return
(
fetchMethod
||
fetch
)
(
uri
,
{
return
fetchMethod
(
uri
,
{
body
:
JSON
.
stringify
(
payload
),
body
:
JSON
.
stringify
(
payload
),
method
:
'
post
'
,
method
:
'
post
'
,
mode
:
'
cors
'
,
mode
:
'
cors
'
,
...
@@ -55,9 +66,7 @@ export default class HttpTransport extends Transport {
...
@@ -55,9 +66,7 @@ export default class HttpTransport extends Transport {
jsonRpc
(
this
.
options
.
uri
,
{
method
:
'
call
'
,
id
,
params
,
fetchMethod
}).
then
(
jsonRpc
(
this
.
options
.
uri
,
{
method
:
'
call
'
,
id
,
params
,
fetchMethod
}).
then
(
res
=>
{
callback
(
null
,
res
);
},
res
=>
{
callback
(
null
,
res
);
},
err
=>
{
err
=>
{
console
.
error
(
'
An error occurred hitting the Steem API:
'
,
err
);
if
(
retriable
.
retry
(
err
))
{
if
(
retriable
.
retry
(
err
))
{
console
.
errror
(
'
Retrying...
'
);
return
;
return
;
}
}
callback
(
retriable
.
mainError
());
callback
(
retriable
.
mainError
());
...
@@ -86,12 +95,12 @@ export default class HttpTransport extends Transport {
...
@@ -86,12 +95,12 @@ export default class HttpTransport extends Transport {
if
(
this
.
nonRetriableOperations
.
some
((
o
)
=>
o
===
data
.
method
))
{
if
(
this
.
nonRetriableOperations
.
some
((
o
)
=>
o
===
data
.
method
))
{
// Do not retry if the operation is non-retriable.
// Do not retry if the operation is non-retriable.
return
null
;
return
null
;
}
else
if
(
Object
(
this
.
options
.
retry
)
===
this
.
options
.
retry
)
{
// If `this.options.retry` is a map of options, pass those to operation.
return
retry
.
operation
(
this
.
options
.
retry
);
}
else
if
(
this
.
options
.
retry
)
{
}
else
if
(
this
.
options
.
retry
)
{
// If `this.options.retry` is a map of options, use it. If
// If `this.options.retry` is `true`, use default options.
// `this.options.retry` is `true`, use default options.
return
retry
.
operation
();
return
(
Object
(
this
.
options
.
retry
)
===
this
.
options
.
retry
)
?
retry
.
operation
(
this
.
options
.
retry
)
:
retry
.
operation
();
}
else
{
}
else
{
// Otherwise, don't retry.
// Otherwise, don't retry.
return
null
;
return
null
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment