<commit_before>////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2008-2013 Esri. All Rights Reserved.
//
// Licensed 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 com.esri.builder.supportClasses
{

import mx.resources.ResourceManager;
import mx.rpc.Fault;

public class ErrorMessageUtil
{
    public static function getKnownErrorCauseMessage(fault:Fault):String
    {
        var message:String;

        switch (fault.faultCode)
        {
            case "Channel.Security.Error":
            {
                message = ResourceManager.getInstance().getString("BuilderStrings", "serverMissingCrossDomain");
                break;
            }
            case "Server.Error.Request":
            case "400":
            case "404":
            {
                message = ResourceManager.getInstance().getString("BuilderStrings", "serviceIsInaccessible");
                break;
            }
            case "499":
            {
                message = ResourceManager.getInstance().getString("BuilderStrings", "unauthorizedAccess");
                break;
            }
            case "403":
            {
                message = ResourceManager.getInstance().getString("BuilderStrings", "resourceAccessDenied");
                break;
            }
            default:
            {
                if (fault.faultString)
                {
                    message = (fault.faultString == "Sign in aborted") ?
                        ResourceManager.getInstance().getString("BuilderStrings", "signInAborted") :
                        fault.faultString;
                }
                else
                {
                    message = ResourceManager.getInstance().getString("BuilderStrings", "unknownErrorCause");
                }
            }
        }

        return message;
    }
}
}<commit_msg>Issue #95: Improve error message utility.<commit_after>////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2008-2013 Esri. All Rights Reserved.
//
// Licensed 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 com.esri.builder.supportClasses
{

import mx.resources.ResourceManager;
import mx.rpc.Fault;

public class ErrorMessageUtil
{
    public static function getKnownErrorCauseMessage(fault:Fault, fallbackErrorMessage:String = null):String
    {
        return getKnownMessageCodeMessage(fault) || getKnownFaultCodeMessage(fault)
            || getKnownFaultStringMessage(fault) || fallbackErrorMessage
            || getString("unknownErrorCause");
    }

    private static function getKnownMessageCodeMessage(fault:Fault):String
    {
        var message:String;

        var messageCode:String;
        var fallbackMessage:String;

        if (fault.content)
        {
            if (fault.content.hasOwnProperty("messageCode"))
            {
                messageCode = fault.content.messageCode;
            }

            if (fault.content.hasOwnProperty("message"))
            {
                fallbackMessage = fault.content.message;
            }
        }

        if (messageCode == "COM_0057")
        {
            message = getString("unableToSignInPortalUser");
        }
        else if (messageCode == "COM_0056")
        {
            message = getString("unableToSignUpPortalUser");
        }

        return message ? message : fallbackMessage;
    }

    private static function getString(key:String):String
    {
        return ResourceManager.getInstance().getString("BuilderStrings", key);
    }

    private static function getKnownFaultCodeMessage(fault:Fault):String
    {
        var message:String;

        var faultCode:String = fault.faultCode;

        if (faultCode == "Channel.Security.Error")
        {
            message = getString("serverMissingCrossDomain");
        }
        else if (faultCode == "400" || faultCode == "404"
            || faultCode == "Server.Error.Request")
        {
            message = getString("serviceIsInaccessible");
        }
        else if (faultCode == "499")
        {
            message = getString("unauthorizedAccess");
        }
        else if (faultCode == "403")
        {
            message = getString("resourceAccessDenied");
        }

        return message;
    }

    private static function getKnownFaultStringMessage(fault:Fault):String
    {
        var message:String;

        var faultString:String = fault.faultString;
        if (faultString)
        {
            message = (faultString == "Sign in aborted") ?
                getString("signInAborted") : faultString;
        }

        return message;
    }
}
}
{'fraction_non_alphanumeric': 0.14575804508690415, 'fraction_numerical': 0.009981070383754948, 'mean_word_length': 1.7428032090608778, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4551595', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1322, 'n_words': 360}