使用JCSOM访问SharePoint时如何捕获未经授权的异常

时间:2014-02-08 09:07:11

标签: sharepoint sharepoint-2013

当用户在组onOperationSucceeded时被调用,否则未经授权的异常“请求失败。访问被拒绝。您没有权限......”我怎样才能实现catch块被击中?

尝试{                 var clientContext = SP.ClientContext.get_current();

            groupCollection = clientContext.get_web().get_siteGroups();
            group = groupCollection.getByName("VR-Administrators"); 

            users = group.get_users();
            clientContext.load(group);
            clientContext.load(users);
            currentUser = clientContext.get_web().get_currentUser();
            clientContext.load(currentUser);

            clientContext.executeQueryAsync(Function.createDelegate(this, onOperationSucceeded), Function.createDelegate(this, onOperationFailed));
        }
        catch(msg)
        {
            alert("Failed!" + msg);
        }

1 个答案:

答案 0 :(得分:1)

SP.ClientContext.executeQueryAsync method在服务器上执行当前待处理请求异步

SP.ClientContext.executeQueryAsync(succeededCallback, failedCallback)

如果请求执行失败,则会调用failedCallback

在您的情况下,以下代码演示了如何处理System.UnauthorizedAccessException异常:

function onOperationFailed(sender,args)
{

   if(args.get_errorTypeName() == "System.UnauthorizedAccessException")
   {
        //Handle UnauthorizedAccessException here..
   }

}