Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp

Issue 2680783002: bluetooth: show better error messages for services, characteristics and descriptors (Closed)
Patch Set: Added comment and changed to enum class. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp
index 383649d5fa405a3c9da61f73c70abbcee2f0525a..bae9bb8c7879e103ada6a1489139b1bf6fe2c15b 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp
@@ -9,15 +9,41 @@
namespace blink {
-DOMException* BluetoothError::take(ScriptPromiseResolver*,
- mojom::blink::WebBluetoothResult error) {
+// static
+DOMException* BluetoothError::createDOMException(
+ BluetoothErrorCode error,
+ const String& detailedMessage) {
+ switch (error) {
+ case BluetoothErrorCode::InvalidService:
+ case BluetoothErrorCode::InvalidCharacteristic:
+ case BluetoothErrorCode::InvalidDescriptor:
+ return DOMException::create(InvalidStateError, detailedMessage);
+ case BluetoothErrorCode::ServiceNotFound:
+ case BluetoothErrorCode::CharacteristicNotFound:
+ case BluetoothErrorCode::DescriptorNotFound:
+ return DOMException::create(NotFoundError, detailedMessage);
+ }
+ NOTREACHED();
+ return DOMException::create(UnknownError);
+}
+
+// static
+DOMException* BluetoothError::createDOMException(
+ mojom::blink::WebBluetoothResult error) {
switch (error) {
case mojom::blink::WebBluetoothResult::SUCCESS:
- ASSERT_NOT_REACHED();
+ case mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND:
+ case mojom::blink::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND:
+ case mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND:
+ // The above result codes are not expected here. SUCCESS is not
+ // an error and the others have a detailed message and are
+ // expected to be redirected to the switch above that handles
+ // BluetoothErrorCode.
+ NOTREACHED();
return DOMException::create(UnknownError);
#define MAP_ERROR(enumeration, name, message) \
case mojom::blink::WebBluetoothResult::enumeration: \
- return DOMException::create(name, message)
+ return DOMException::create(name, message);
// InvalidModificationErrors:
MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError,
@@ -68,6 +94,17 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*,
"GATT operation already in progress.");
MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError,
"Unknown ConnectErrorCode.");
+ MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError,
+ "GATT Server is disconnected. Cannot perform GATT operations.");
+ MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError,
+ "GATT Server disconnected while performing a GATT operation.");
+ MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS,
+ NetworkError,
+ "GATT Server disconnected while retrieving characteristics.");
+ MAP_ERROR(
+ GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS,
+ NetworkError,
+ "GATT Server is disconnected. Cannot retrieve characteristics.");
// NotFoundErrors:
MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError,
@@ -86,16 +123,10 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*,
MAP_ERROR(
CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN, NotFoundError,
"User denied the browser permission to scan for Bluetooth devices.");
- MAP_ERROR(SERVICE_NOT_FOUND, NotFoundError,
- "No Services with specified UUID found in Device.");
MAP_ERROR(NO_SERVICES_FOUND, NotFoundError,
"No Services found in device.");
- MAP_ERROR(CHARACTERISTIC_NOT_FOUND, NotFoundError,
- "No Characteristics with specified UUID found in Service.");
MAP_ERROR(NO_CHARACTERISTICS_FOUND, NotFoundError,
"No Characteristics found in service.");
- MAP_ERROR(DESCRIPTOR_NOT_FOUND, NotFoundError,
- "No Descriptors with specified UUID found in Characteristic.");
MAP_ERROR(NO_DESCRIPTORS_FOUND, NotFoundError,
"No Descriptors found in Characteristic.");
MAP_ERROR(BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, NotFoundError,
@@ -140,13 +171,11 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*,
"UUID. https://goo.gl/4NeimX");
MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError,
"requestDevice() called from cross-origin iframe.");
- MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError,
- "No window to show the requestDevice() dialog.");
#undef MAP_ERROR
}
- ASSERT_NOT_REACHED();
+ NOTREACHED();
return DOMException::create(UnknownError);
}

Powered by Google App Engine
This is Rietveld 408576698