aharui closed pull request #340: URLLoader: HTTPStatusEvent addition URL: https://github.com/apache/royale-asjs/pull/340
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/frameworks/projects/Network/src/main/royale/NetworkClasses.as b/frameworks/projects/Network/src/main/royale/NetworkClasses.as index 902c70e49..b905d8825 100644 --- a/frameworks/projects/Network/src/main/royale/NetworkClasses.as +++ b/frameworks/projects/Network/src/main/royale/NetworkClasses.as @@ -32,6 +32,10 @@ package import org.apache.royale.net.URLBinaryUploader; URLBinaryUploader; import org.apache.royale.net.events.ResultEvent; ResultEvent; import org.apache.royale.net.events.FaultEvent; FaultEvent; + COMPILE::JS + { + import org.apache.royale.net.events.HTTPStatusEvent; HTTPStatusEvent; + } import org.apache.royale.net.remoting.messages.AcknowledgeMessage; AcknowledgeMessage; import org.apache.royale.net.remoting.messages.AcknowledgeMessageExt; diff --git a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLLoader.as b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLLoader.as index 0ee6e3547..b3a2faab1 100644 --- a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLLoader.as +++ b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/URLLoader.as @@ -27,6 +27,10 @@ package org.apache.royale.net import flash.net.URLRequest; import flash.net.URLRequestHeader; } + COMPILE::JS + { + import org.apache.royale.net.events.HTTPStatusEvent; + } import org.apache.royale.events.DetailEvent; import org.apache.royale.events.Event; @@ -266,9 +270,16 @@ package org.apache.royale.net var element:XMLHttpRequest = this.element as XMLHttpRequest; if (element.readyState == 2) { dispatchEvent(HTTPConstants.RESPONSE_STATUS); - dispatchEvent(HTTPConstants.STATUS); + dispatchEvent( new HTTPStatusEvent(element.status) ); } else if (element.readyState == 4) { - dispatchEvent(HTTPConstants.COMPLETE); + if (element.status >= 400) // client error or server error + { + dispatchEvent(HTTPConstants.IO_ERROR); + } + else + { + dispatchEvent(HTTPConstants.COMPLETE); + } } } diff --git a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/events/HTTPStatusEvent.as b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/events/HTTPStatusEvent.as new file mode 100644 index 000000000..ff6d62b91 --- /dev/null +++ b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/events/HTTPStatusEvent.as @@ -0,0 +1,39 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.net.events +{ + import org.apache.royale.events.Event; + import org.apache.royale.net.URLLoader; + + /** + * HTTPStatusEvent is dispatched from a URLLoader + * when it receives readyState = 2 with an HTTP + * status code. + */ + public class HTTPStatusEvent extends Event + { + public static const HTTP_STATUS:String = "httpStatus"; + public var status:uint; + public function HTTPStatusEvent(statusCode:uint, bubbles:Boolean = false, cancelable:Boolean = true) + { + super(HTTP_STATUS, bubbles, cancelable); + status = statusCode; + } + } +} ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services