提问者:小点点

处理Autodesk Forge Viewer的错误


我使用以下JavaScript代码在欧特克Forge Viewer中显示模型:

var options = {
    'document': 'urn:' + urn,
    'env': 'AutodeskProduction',
    'getAccessToken': getToken,
    'refreshToken': getToken
};
Autodesk.Viewing.Initializer(options, function () {
    Autodesk.Viewing.Document.load(options.document,
        function (doc) { // onSuccessCallback
            // load the viewer
        },
        function (errorCode) { // onErrorCallback
            interval = setInterval(function () {
                $.ajax({
                    url: 'https://developer.api.autodesk.com' + '/viewingservice/v1/' + urn,
                    type: 'GET',
                    headers: { Authorization: 'Bearer ' + getToken() },
                    success: function (i) {
                        switch (i.status) {
                            case 'success':
                                // load the viewer
                                break;
                            case 'failed':
                            case 'timeout':
                                // report error
                                break;
                            case 'inprogress':
                                break;
                            default:
                                break;
                        }
                    },
                    error: function (b, d, e) {
                        // report error
                    }
                });
            }, 3000); // Repeatedly request the viewing service for each 3 seconds
        }
    );
});

onSuccessCallback:它将在查看器中显示模型。

OneErrorCallback:它将继续发布查看服务,直到获得“成功”状态。如果状态为“失败”或“超时”,它将向用户报告他们无法查看此模型。

在Autodesk之后。观看。文件加载(options.document),它将跳转到errorCode==9(“获取的文档中没有任何可见内容”)。然后我不断请求查看服务从中获取结果。以下是错误代码列表:

var errorCodes = {
    1: 'An unknown failure has occurred.',
    2: 'Bad data (corrupted or malformed) was encountered.',
    3: 'A network failure was encountered.',
    4: 'Access was denied to a network resource (HTTP 403)',
    5: 'A network resource could not be found (HTTP 404)',
    6: 'A server error was returned when accessing a network resource (HTTP 5xx)',
    7: 'An unhandled response code was returned when accessing a network resource (HTTP "everything else")',
    8: 'Browser error: webGL is not supported by the current browser',
    9: 'There is nothing viewable in the fetched document',
    10: 'Browser error: webGL is supported, but not enabled',
    11: 'There is no geomtry in loaded model',
    12: 'Collaboration server error'
};

问题是有时它返回到状态=='失败'(在Revit中)或状态=='超时'(在Inventor中)而没有更多细节。它发生在一些Revit/Inventor文件上,而不是所有的案例。

如何要求Forge查看服务重新翻译这些文件以显示回web浏览器。对查看服务的请求总是失败。因此,这些文件没有机会在Forge viewer中显示。


共2个答案

匿名用户

首先,也是非常重要的,你不应该从客户那里打电话给翻译。这意味着您的getToken方法返回具有写入功能的令牌,因此恶意用户可以使用它访问和修改您的文件。您的客户端应该只看到只读令牌。考虑在服务器上使用写令牌和客户机上的读令牌(对于Autodesk查看器)。

其次,您应该在JOBendpoint上使用Autodesk-mode-派生API的v2,其中MANIFESTendpoint将为您提供翻译的完整描述(正在进行或已完成/失败)。以前的v1视图

匿名用户

使用v2 API:如果初始翻译失败,要重新提交翻译,您需要删除现有清单并重新提交svf作业。

使用v1api:您可以使用“x-ads-force”=true标志重新提交注册请求。请参见此处的示例。