Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Latest commit

 

History

History
51 lines (34 loc) · 2.64 KB

errors.md

File metadata and controls

51 lines (34 loc) · 2.64 KB

Handling errors in the OneDrive SDK for iOS

Errors in the OneDriveSDK for iOS behave just like errors returned from the service. You can read more about them here.

Anytime you make a request against the service there is the potential for an error. You will see that all requests to the service can return an error. The error returned is a native NSError object, and inside of the NSErrors user dictionary you can obtain the ODError object.

Checking the Error

There are a few different types of errors that can occur during a network call. We have provided some helper methods to make it easy to check what kind of error occurred. These error types are defined in ODAuthContants.h.

Authentication Errors

There can be errors during the authentication process. If the error occurred during the authentication process, the error will have the domain OD_AUTH_ERROR_DOMAIN, which is defined as com.microsoft.onedrivesdk.auth in ODAuthContants.h.

You can easily check if an error is an authentication error by calling [error IsAuthenticationError]:

[ODClient clientWithCompletion:^(ODClient *client, NSError *error){
    if (error && [error isAuthenticationError]){
        // handle auth error
    }
 }];

In this case, you can also call [error IsAuthCancelError] to check if the user canceled the auth flow themselves.

See ODAuthConstants.h for a list of error codes during authentication. To retrieve any info about the error, look in the userInfo dictionary with the key OD_AUTH_ERROR_KEY, which is defined as ODAuthErrorKey.

Client Errors

To check if an error is a client error, you can call [error isClientError] and [error clientError], like this:

[[[[odClient drive] items:@"foo"] request] getWithCompletion:^(ODItem *item, NSError *error){
    if (error && [error isClientError]){
        [self handleClientError:[error clientError]];
    }
}];

When a client error arises there will be an ODError object stored in the userInfo dictionary. You can access it with ODErrorKey, defined in ODConstants.h.

To check the code of an error, you can call the matches method on an error:

if ([odError matches:@"accessDenied"]){
    // handle access denied error
}

Each error object has a message as well as code. This message is for debugging purpose and is not be meant to be displayed to the user. Common error codes have been defined in ODErrorCodes.h.