예제 #1
0
        public static IQ ToCustomError(this IQ iq, ErrorType type = ErrorType.@continue, int code = 8, int custom_code = -1, string text = "Custom query error.")
        {
            iq.SwitchDirection();
            iq.Type = IqType.error;

            iq.C("error")
            .A("type", type.ToString())
            .A("code", code)
            .A("custom_code", custom_code)
            .C("text", text, Namespaces.STANZAS);

            return(iq);
        }
예제 #2
0
        public static IQ ToError(this IQ iq, ErrorType type = ErrorType.cancel, ErrorCondition condition = ErrorCondition.FeatureNotImplemented, string text = "Custom query error.")
        {
            iq.SwitchDirection();
            iq.Type = IqType.error;

            var tag = "";

            switch (condition)
            {
            case ErrorCondition.BadRequest: tag = "bad-request"; break;

            case ErrorCondition.Conflict: tag = "conflict"; break;

            case ErrorCondition.FeatureNotImplemented: tag = "feature-not-implemented"; break;

            case ErrorCondition.Forbidden: tag = "forbidden"; break;

            case ErrorCondition.Gone: tag = "gone"; break;

            case ErrorCondition.InternalServerError: tag = "internal-server-error"; break;

            case ErrorCondition.ItemNotFound: tag = "item-not-found"; break;

            case ErrorCondition.JidMalformed: tag = "jid-malformed"; break;

            case ErrorCondition.NotAcceptable: tag = "not-acceptable"; break;

            case ErrorCondition.NotAllowed: tag = "not-allowed"; break;

            case ErrorCondition.NotAuthorized: tag = "not-authorized"; break;

            case ErrorCondition.NotModified: tag = "not-modified"; break;

            case ErrorCondition.PaymentRequired: tag = "payment-required"; break;

            case ErrorCondition.RecipientUnavailable: tag = "recipient-unavailable"; break;

            case ErrorCondition.Redirect: tag = "redirect"; break;

            case ErrorCondition.RegistrationRequired: tag = "registration-required"; break;

            case ErrorCondition.RemoteServerNotFound: tag = "remote-server-not-found"; break;

            case ErrorCondition.RemoteServerTimeout: tag = "remote-server-timeout"; break;

            case ErrorCondition.ResourceConstraint: tag = "resource-constraint"; break;

            case ErrorCondition.ServiceUnavailable: tag = "service-unavailable"; break;

            case ErrorCondition.SubscriptionRequired: tag = "subscription-required"; break;

            case ErrorCondition.UndefinedCondition: tag = "undefined-condition"; break;

            case ErrorCondition.UnexpectedRequest: tag = "unexpected-request"; break;

            default: tag = "undefined-condition"; break;
            }

            iq.C("error")
            .A("type", type.ToString())
            .C(tag, ns: Namespaces.STANZAS);

            return(iq);
        }