|
78 | 78 | import org.htmlunit.javascript.configuration.JsxSetter; |
79 | 79 | import org.htmlunit.javascript.host.URLSearchParams; |
80 | 80 | import org.htmlunit.javascript.host.Window; |
| 81 | +import org.htmlunit.javascript.host.dom.DOMException; |
81 | 82 | import org.htmlunit.javascript.host.dom.DOMParser; |
82 | 83 | import org.htmlunit.javascript.host.dom.Document; |
83 | 84 | import org.htmlunit.javascript.host.event.Event; |
@@ -278,8 +279,11 @@ public void setResponseType(final String responseType) { |
278 | 279 | || RESPONSE_TYPE_TEXT.equals(responseType)) { |
279 | 280 |
|
280 | 281 | if (state_ == OPENED && !async_) { |
281 | | - throw JavaScriptEngine.reportRuntimeError( |
282 | | - "InvalidAccessError: synchronous XMLHttpRequests do not support responseType"); |
| 282 | + throw JavaScriptEngine.asJavaScriptException( |
| 283 | + getWindow(), |
| 284 | + new DOMException( |
| 285 | + "synchronous XMLHttpRequests do not support responseType", |
| 286 | + DOMException.INVALID_ACCESS_ERR)); |
283 | 287 | } |
284 | 288 |
|
285 | 289 | responseType_ = responseType; |
@@ -450,10 +454,13 @@ public String getResponseText() { |
450 | 454 | } |
451 | 455 |
|
452 | 456 | if (!RESPONSE_TYPE_DEFAULT.equals(responseType_) && !RESPONSE_TYPE_TEXT.equals(responseType_)) { |
453 | | - throw JavaScriptEngine.reportRuntimeError( |
454 | | - "InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': " |
455 | | - + "The value is only accessible if the object's 'responseType' is '' or 'text' " |
456 | | - + "(was '" + getResponseType() + "')."); |
| 457 | + throw JavaScriptEngine.asJavaScriptException( |
| 458 | + getWindow(), |
| 459 | + new DOMException( |
| 460 | + "InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': " |
| 461 | + + "The value is only accessible if the object's 'responseType' is '' or 'text' " |
| 462 | + + "(was '" + getResponseType() + "').", |
| 463 | + DOMException.INVALID_STATE_ERR)); |
457 | 464 | } |
458 | 465 |
|
459 | 466 | if (state_ == UNSENT || state_ == OPENED) { |
@@ -953,8 +960,7 @@ void doSend() { |
953 | 960 | if (LOG.isDebugEnabled()) { |
954 | 961 | LOG.debug("No permitted request for URL " + webRequest_.getUrl()); |
955 | 962 | } |
956 | | - throw JavaScriptEngine.throwAsScriptRuntimeEx( |
957 | | - new RuntimeException("No permitted \"Access-Control-Allow-Origin\" header.")); |
| 963 | + throw JavaScriptEngine.networkError("No permitted \"Access-Control-Allow-Origin\" header."); |
958 | 964 | } |
959 | 965 | } |
960 | 966 |
|
@@ -1075,7 +1081,7 @@ public Charset getContentCharset() { |
1075 | 1081 | fireJavascriptEvent(Event.TYPE_LOAD_END); |
1076 | 1082 | } |
1077 | 1083 |
|
1078 | | - throw JavaScriptEngine.throwAsScriptRuntimeEx(e); |
| 1084 | + throw JavaScriptEngine.networkError(e.getMessage()); |
1079 | 1085 | } |
1080 | 1086 | } |
1081 | 1087 | } |
@@ -1202,7 +1208,11 @@ static boolean isAuthorizedHeader(final String name) { |
1202 | 1208 | @JsxFunction |
1203 | 1209 | public void overrideMimeType(final String mimeType) { |
1204 | 1210 | if (state_ != UNSENT && state_ != OPENED) { |
1205 | | - throw JavaScriptEngine.reportRuntimeError("Property 'overrideMimeType' not writable after sent."); |
| 1211 | + throw JavaScriptEngine.asJavaScriptException( |
| 1212 | + getWindow(), |
| 1213 | + new DOMException( |
| 1214 | + "Property 'overrideMimeType' not writable after sent.", |
| 1215 | + DOMException.INVALID_STATE_ERR)); |
1206 | 1216 | } |
1207 | 1217 | overriddenMimeType_ = mimeType; |
1208 | 1218 | } |
|
0 commit comments