Opened 15 years ago

Closed 15 years ago

#1083 closed defect (fixed)

Report meaningful error message without changing MapAgent status text

Reported by: christinebao Owned by: Chris Claydon
Priority: medium Milestone: 2.2
Component: Fusion Version: 2.0.2
Severity: major Keywords:
Cc: External ID: 1246885

Description

Cause:
RFC http://trac.osgeo.org/mapguide/wiki/MapGuideRfc66 (Prevent session timeout, and give better error messages) requires to show meaningful error message if server exception happens. Previously the error message displayed exception type such as

FATAL: xml2json: invalid XML document: '''MgConnectionFailedException''' : http://127.0.0.1/mapguide2010/mapagent/mapagent.fcgi?version=1.0.0&locale=en&clientagent=Fusion%20Viewer&operation=QUERYMAPFEATURES&session=40d3e074-3ee5-102c-8000-005056c00008_en_7F0000010AFC0AFB0AFA&mapname=Sheboygan4a3b609791c82&geometry=POLYGON((-87.730254250931%2043.73763292302%2C%20-87.730254250931%2043.737069942268%2C%20-87.729691270179%2043.737069942268%2C%20-87.729691270179%2043.73763292302%2C%20-87.730254250931%2043.73763292302))&maxFeatures=1&persist=0&selectionVariant=INTERSECTS&layerNames=&layerAttributeFilter=5 type=0

However this is not user-friendly for end users. A localizable exception message is preferred rather than class name. As the content of error message is from fusion error handler

        xml2json: function(callback, r, json) {
            if (json) {
                var o;
                eval("o=" + r.responseText);
                callback(o);
            } else {
                if (r.status >= 400) {
                    Fusion.reportError(new Fusion.Error(Fusion.Error.FATAL,
                  'xml2json: invalid XML document: ' + '''r.statusText''' + " : " + r.request.url));
                    return;
                }
}}}[[BR]]
A solution is to set exception message instead of exception class name as XmlHttpRequest (r) status text. Take CgiAgent for example, the code is changed to follow (please pay attention to status text, which is set as shortError, equal exception message):[[BR]]
{{{
void CgiResponseHandler::SendError(MgException* e)
{
    MG_TRY()
    STRING shortError = e->GetMessage();
    STRING longError = e->GetDetails();
    STRING statusMessage = e->GetClassName();

    //TODO: Use a string resource for html error text format
    printf(MapAgentStrings::StatusHeader, 559, MG_WCHAR_TO_CHAR(shortError));
    printf(MapAgentStrings::ContentTypeHeader, MapAgentStrings::TextHtml, MapAgentStrings::Utf8Text);
    printf("\r\n"
        "<html>\n<head>\n"
        "<title>%s</title>\n"
        "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"
        "</head>\n"
        "<body>\n<h2>%s</h2>\n%s\n</body>\n</html>\n",
        MG_WCHAR_TO_CHAR(statusMessage),
        MG_WCHAR_TO_CHAR(shortError),
        MG_WCHAR_TO_CHAR(longError));

    DumpMessage(MG_WCHAR_TO_CHAR(longError));

    MG_CATCH(L"CgiResponseHandler.SendError")
}
}}}

'''Problem:'''[[BR]]
This solution works for RFC requirement, however it brings risk for other applications which depend on checking status text. [[BR]]
One case is Web Tier unit test, which creates scenerios to throw server exception and verify them by status text. After changing the MapAgent code, all the related test cases fail.[[BR]]
Another case is from Autodesk QA, that Studio has a code as below:[[BR]]
{{{
MgDev\Common\Gis\Site\SiteManager.cs(400)
                        if (we.Message.Contains("(559)")) //NOXLATE
                            if (we.Message.Contains("MgConnectionFailedException"))  
                                return ConnectionStatus.UnreachableServer;

}}}
[[BR]]
There could be more cases potentially fail because of MapAgent change.

'''Solution:'''[[BR]]
Based on the defects reporting, a solution is needed to show meaningful error message without changing MapAgent status text. This is possible. When looking at the content of MapAgent response handler, it's found that all the information (exception class name, exception message) are formatted as an HTML content. And this can be got in fusion by r.transport.responseText.[[BR]]
So a solution is:[[BR]]
1. Rollback MapAgent code, exception class name is still be used as status text.[[BR]]
2. Fusion returns r.transport.responseText instead of r.statusText in error handler.[[BR]]
3. MapGuide templates parse r.transport.responseText to get meaningful exception message and display.[[BR]]



Attachments (4)

RollbackMapAgent.patch (4.4 KB ) - added by christinebao 15 years ago.
FusionErrorHandling.patch (536 bytes ) - added by christinebao 15 years ago.
MGTemplateErrorHandling.patch (9.6 KB ) - added by christinebao 15 years ago.
RollbackWebTierTest.patch (2.1 MB ) - added by christinebao 15 years ago.

Change History (11)

comment:1 by christinebao, 15 years ago

Oops, how can I re-format the content of description?

by christinebao, 15 years ago

Attachment: RollbackMapAgent.patch added

comment:2 by christinebao, 15 years ago

Attach patch https://trac.osgeo.org/mapguide/attachment/ticket/1083/RollbackMapAgent.patch.

This patch rollback the changes in MapAgent. MapAgent will remain the same as before to avoid potential affect to other applications.

by christinebao, 15 years ago

Attachment: FusionErrorHandling.patch added

comment:3 by christinebao, 15 years ago

Attach patch https://trac.osgeo.org/mapguide/attachment/ticket/1083/FusionErrorHandling.patch.

This patch modified the error handling code of fusion, making the error handler returned message contains r.transport.responseText instead of r.statusText. r.transport.responseText is a formatted HTML content containing both class name and exception message, such as:

<html>
  <head>
    <title>MgSessionExpiredException</title>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  </head>
  <body>
    <h2>Session has expired or is invalid. Please log in again.</h2>
    Session has expired or is invalid. Please log in again.
  </body>
</html>

by christinebao, 15 years ago

comment:4 by christinebao, 15 years ago

Attach patch https://trac.osgeo.org/mapguide/attachment/ticket/1083/MGTemplateErrorHandling.patch.

This patch modified the parse in MapGuide template for error handling, and get the content between <h2> and </h2> to display on browser alert.

by christinebao, 15 years ago

Attachment: RollbackWebTierTest.patch added

comment:5 by christinebao, 15 years ago

Attach patch https://trac.osgeo.org/mapguide/attachment/ticket/1083/RollbackWebTierTest.patch.

Previously because MapAgent was changed, the unit test data of web tier was updated also. Now as MapAgent remains unchanged, the test data should be rollback to previous.

comment:6 by chrisclaydon, 15 years ago

Submitted patches on behalf of Christine Bao:

Rollback map agent:

http://trac.osgeo.org/mapguide/changeset/4228

MG template error handling:

http://trac.osgeo.org/mapguide/changeset/4229

Rollback web tier test:

http://trac.osgeo.org/mapguide/changeset/4230

Fusion error handling:

http://trac.osgeo.org/fusion/changeset/1896

comment:7 by christinebao, 15 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.