| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/bluetooth/BluetoothError.h" | 5 #include "modules/bluetooth/BluetoothError.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 DOMException* BluetoothError::take(ScriptPromiseResolver*, | 12 DOMException* BluetoothError::take(ScriptPromiseResolver* resolver, |
| 13 mojom::blink::WebBluetoothResult error) { | 13 mojom::blink::WebBluetoothResult error) { |
| 14 return take(resolver, error, String()); |
| 15 } |
| 16 |
| 17 DOMException* BluetoothError::take(ScriptPromiseResolver* resolver, |
| 18 mojom::blink::WebBluetoothResult error, |
| 19 String detailedMessage) { |
| 14 switch (error) { | 20 switch (error) { |
| 15 case mojom::blink::WebBluetoothResult::SUCCESS: | 21 case mojom::blink::WebBluetoothResult::SUCCESS: |
| 16 ASSERT_NOT_REACHED(); | 22 ASSERT_NOT_REACHED(); |
| 17 return DOMException::create(UnknownError); | 23 return DOMException::create(UnknownError); |
| 18 #define MAP_ERROR(enumeration, name, message) \ | 24 #define MAP_ERROR(enumeration, name, message) \ |
| 19 case mojom::blink::WebBluetoothResult::enumeration: \ | 25 case mojom::blink::WebBluetoothResult::enumeration: \ |
| 20 return DOMException::create(name, message) | 26 if (detailedMessage.isEmpty()) { \ |
| 27 return DOMException::create(name, message); \ |
| 28 } else { \ |
| 29 return DOMException::create(name, detailedMessage); \ |
| 30 } |
| 21 | 31 |
| 22 // InvalidModificationErrors: | 32 // InvalidModificationErrors: |
| 23 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, | 33 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| 24 "GATT Error: invalid attribute length."); | 34 "GATT Error: invalid attribute length."); |
| 25 | 35 |
| 26 // InvalidStateErrors: | 36 // InvalidStateErrors: |
| 27 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, | 37 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, |
| 28 "GATT Service no longer exists."); | 38 "GATT Service no longer exists."); |
| 29 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, | 39 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, |
| 30 "GATT Characteristic no longer exists."); | 40 "GATT Characteristic no longer exists."); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 "No window to show the requestDevice() dialog."); | 154 "No window to show the requestDevice() dialog."); |
| 145 | 155 |
| 146 #undef MAP_ERROR | 156 #undef MAP_ERROR |
| 147 } | 157 } |
| 148 | 158 |
| 149 ASSERT_NOT_REACHED(); | 159 ASSERT_NOT_REACHED(); |
| 150 return DOMException::create(UnknownError); | 160 return DOMException::create(UnknownError); |
| 151 } | 161 } |
| 152 | 162 |
| 153 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |