Comments (3)
It all has to do with what you are trying to achieve. The way it is currently designed, your app will not get the rpcResponse.Error
details, however an exception will be raised (try adding a FirstChanceException
handler to your AppDomain
: AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler;
), so as long as you perform your crucial RPC calls in a Try/Catch
block the current implementation will serve as a production-level framework for your app. If on the other hand you believe that the rpcResponse.Error
's content is crucial for your app then you can throw an exception (or even execute any custom exception handling code) as-it-happens:
public T MakeRequest<T>(RpcMethods rpcMethod, params object[] parameters)
{
JsonRpcResponse<T> rpcResponse = MakeRpcRequest<T>(new JsonRpcRequest(1, rpcMethod.ToString(), parameters), 0);
if (!String.IsNullOrWhiteSpace(rpcResponse.Error))
{
throw new Exception(rpcResponse.Error);
}
return rpcResponse.Result;
}
For RPC methods that return String or Object, this will suffice:
return String.IsNullOrEmpty(rpcResponse.Error) ? rpcResponse.Result : (T)(object)rpcResponse.Error;
I will be adding the rpcResponse.Error
handling code, as demonstrated above, along with a config
parameter to control whether an exception should be raised from the wrapper to the next release, unless there is something more you would like to add on top of that.
from bitcoinlib.
Hi,
Many thanks for the detailed answer.
Right now my project it on a halt, hence the late response…
I’m not a professional developer, therefore :
-
some of what you propose maybe seems awkward to me when maybe it shouldn’t.
-
some of my thoughts may be nonsense to you.
Here goes anyway:
I feel the idea that you get a real JSON response, that contains information (though only in the error section), is ending up as an exception, is weird to me. It’s as if you are overriding the protocol behavior to some simplified other thing.
I would rather get the full object of Result+Error, which contain the collections, then the collection themselves, if there is a high risk of getting errors (and with my experience with wallets, there are risks of errors, and I would want to propagate as much of it as possible to the application).
Since others may think differently, and maybe this makes sense in some cases only, my recommendation would be to offer alternative methods that return a full response object (containing result with relevant collection inside + string error), and not the underlying collection that comes in case of success
I guess you’d know the elegant way of implementing it, or completely ignore if it does not make any sense to you.
As for AppDomain: AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler. I’m not sure I know how this would work, but if this behave like some kind of a sink, where I can log that the exception occurred, it won’t really help.
Before I decided the right way to use your code was without any changes to it, I was doing the following:
public T MakeRequest(RpcMethods rpcMethod, params object[] parameters)
{
JsonRpcResponse<T> rpcResponse = MakeRpcRequest<T>(new JsonRpcRequest(1, rpcMethod.ToString(), parameters), 0);
if (rpcResponse == null)
return default(T);
else
return rpcResponse.Result;
}
Please consider, maybe throwing the exception with the Error inside and then returning default(T), would be a good compromise
Regards,
Guy
From: George Kimionis [mailto:[email protected]]
Sent: Sunday, July 6, 2014 4:35 PM
To: GeorgeKimionis/BitcoinLib
Cc: 3strategy
Subject: Re: [BitcoinLib] Issue? / workaround inside public T MakeRequest !? (#14)
It all has to do with what you are trying to achieve. The way it is currently designed, your app will not get the rpcResponse.Error details, however an exception will be raised (try adding a FirstChanceException handler to your AppDomain: AppDomain.CurrentDomain.FirstChanceException += FirstChanceExceptionHandler;), so as long as you perform your crucial RPC calls in a Try/Catch block the current implementation will serve as a production-level framework for your app. If on the other hand you believe that the rpcResponse.Error's content is crucial for your app then you can throw an exception (or even execute any custom exception handling code) as-it-happens:
public T MakeRequest<T>(RpcMethods rpcMethod, params object[] parameters)
{
JsonRpcResponse<T> rpcResponse = MakeRpcRequest<T>(new JsonRpcRequest(1, rpcMethod.ToString(), parameters), 0);
if (!String.IsNullOrWhiteSpace(rpcResponse.Error))
{
throw new Exception(rpcResponse.Error);
}
return rpcResponse.Result;
}
For RPC methods that return String or Object, this will suffice:
return String.IsNullOrEmpty(rpcResponse.Error) ? rpcResponse.Result : (T)(object)rpcResponse.Error;
I will be adding the rpcResponse.Error handling code, as demonstrated above, along with a config parameter to control whether an exception should be raised from the wrapper to the next release, unless there is something more you would like to add on top of that.
—
Reply to this email directly or view it on GitHub #14 (comment) .
from bitcoinlib.
This is now resolved with the use of RpcInternalServerErrorException()
that handles internal server error exceptions and rebroadcast both the error message as well as the RPC error code.
from bitcoinlib.
Related Issues (20)
- Add createwallet HOT 1
- It produces errors with bitcoin core 0.17.1 HOT 4
- Add documentation comments to methods showing which units are returned HOT 1
- GetBlockResponse does not contain weight
- bitcoinlib support .net core? HOT 1
- NetworkHashPS exceeds Int64.Max resulting in overflow HOT 1
- GetRawMemPool(true) throws exception HOT 4
- Is this repo still maintained? HOT 6
- GetBlockTemplate no longer works HOT 4
- Add support for secure (.cookie) auth
- IsWalletEncrypted returns false positive
- Getting - Dummy value must be set to "" - after some of the method calls HOT 6
- Various 'Wallet' RPC Calls Require URL with '/wallet/<wallet-name>' appended HOT 1
- DecodeRawTransaction does not populate addresses
- GetAccount method returns empty string HOT 2
- ListSinceBlock passing wrong parameter by default HOT 4
- How to create transactions that carry messages in OP_RETURN HOT 2
- Getblocktemplate does not provide txid, only hash HOT 3
- No support for new label system HOT 4
- Exception while DumpWallet method HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitcoinlib.