diff options
author | zakorgy <zakorgy@inf.u-szeged.hu> | 2016-07-21 12:41:47 +0200 |
---|---|---|
committer | zakorgyula <gyula.zakor@gmail.com> | 2016-07-27 15:02:01 +0200 |
commit | b4db14471bb6273e681a7f4945a4f8d0d9a6c8ea (patch) | |
tree | 6641b4f5f2b93ce772429bcfc1ec49a4371caa7e /components/script/dom/bluetooth.rs | |
parent | d8991496c6ddcce3c93ba36d36619a3200626c1f (diff) | |
download | servo-b4db14471bb6273e681a7f4945a4f8d0d9a6c8ea.tar.gz servo-b4db14471bb6273e681a7f4945a4f8d0d9a6c8ea.zip |
Refactor Bluetooth error handling
Diffstat (limited to 'components/script/dom/bluetooth.rs')
-rw-r--r-- | components/script/dom/bluetooth.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 7deca26c9d3..c86fa0150a3 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -7,7 +7,7 @@ use core::clone::Clone; use dom::bindings::codegen::Bindings::BluetoothBinding; use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions; use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothScanFilter, BluetoothMethods}; -use dom::bindings::error::Error::{Security, Type}; +use dom::bindings::error::Error::{self, Security, Type}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; @@ -19,7 +19,7 @@ use dom::bluetoothuuid::BluetoothUUID; use ipc_channel::ipc::{self, IpcSender}; use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; +use net_traits::bluetooth_thread::{BluetoothError, BluetoothMethodMsg}; const FILTER_EMPTY_ERROR: &'static str = "'filters' member must be non - empty to find any devices."; const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way."; @@ -135,6 +135,18 @@ fn convert_request_device_options(options: &RequestDeviceOptions, ServiceUUIDSequence::new(optional_services))) } +impl From<BluetoothError> for Error { + fn from(error: BluetoothError) -> Self { + match error { + BluetoothError::Type(message) => Error::Type(message), + BluetoothError::Network => Error::Network, + BluetoothError::NotFound => Error::NotFound, + BluetoothError::NotSupported => Error::NotSupported, + BluetoothError::Security => Error::Security, + } + } +} + impl BluetoothMethods for Bluetooth { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice fn RequestDevice(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> { @@ -154,7 +166,7 @@ impl BluetoothMethods for Bluetooth { &ad_data)) }, Err(error) => { - Err(Type(error)) + Err(Error::from(error)) }, } } |