-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request error handling #23
base: master
Are you sure you want to change the base?
Changes from all commits
2d6d72d
f2864dd
c9d2a56
ee68f18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace MasterDevs.ChromeDevTools | ||
{ | ||
public interface ICommandResponseWrapper<T> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @svatal any reason not to merge the ICommandResponse and ICommandResponseWrapper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been afraid how deserialization would cope with a class that have something more than a basic properties. Did not tested it though. |
||
{ | ||
long Id { get; } | ||
string Method { get; } | ||
bool IsError(); | ||
T Result { get; } | ||
Error Error { get; } | ||
} | ||
|
||
public class CommandResponseWrapper<T> : ICommandResponseWrapper<T> | ||
{ | ||
private readonly ICommandResponse _response; | ||
|
||
public CommandResponseWrapper(ICommandResponse response) | ||
{ | ||
_response = response; | ||
} | ||
|
||
public long Id => _response.Id; | ||
public string Method => _response.Method; | ||
|
||
public bool IsError() => _response is IErrorResponse; | ||
|
||
public T Result | ||
{ | ||
get | ||
{ | ||
var commandResponse = _response as CommandResponse<T>; | ||
if (commandResponse != null) | ||
return commandResponse.Result; | ||
throw new ResultNotAvailableException((IErrorResponse)_response, typeof(T)); | ||
} | ||
} | ||
|
||
public Error Error => (_response as IErrorResponse)?.Error; | ||
} | ||
|
||
public class ResultNotAvailableException : Exception | ||
{ | ||
public ResultNotAvailableException(IErrorResponse response, Type type) | ||
: base($"Unhandled command error {{ Code: {response.Error.Code}, Message: {response.Error.Message} }} to command {response.Id} requesting {type}.") | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
namespace MasterDevs.ChromeDevTools | ||
using System; | ||
|
||
namespace MasterDevs.ChromeDevTools | ||
{ | ||
public interface IChromeSessionFactory | ||
{ | ||
IChromeSession Create(string endpointUrl); | ||
IChromeSession Create(string endpointUrl, Action<Exception> onError); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onError
should be optional. If it's not provided, it shouldthrow
by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a breaking change, but if we keep the throwing behaviour, there is no place to catch it - since it can occur on another thread while recieving event from chrome.
Are you sure you really want to keep this behaviour by default instead of forcing user to handle it?