# Handling errors

# Overview

Several error codes are defined in the LINE SDK to help you locate the reason when an error occurs. In the LINE SDK, the NSError class is used to represent an error.

# SDK internal error

The LineSDKInternalErrorCode enumeration defines internal errors and error codes reported by the SDK. These errors cover most cases.

LineSDKInternalErrorCode Error code number
LineSDKInternalErrorCodeLoginError 1
LineSDKInternalErrorCodeMissingConfiguration 2
LineSDKInternalErrorCodeAuthenticationCanceled 3
LineSDKInternalErrorCodeMissingAccessToken 4
LineSDKInternalErrorCodeInvalidTokenType 5
LineSDKInternalErrorCodeMissingRequiredField 6
LineSDKInternalErrorCodeInvalidValueType 7
LineSDKInternalErrorCodeInvalidJSONWebKeyType 8
LineSDKInternalErrorCodeTokenIDVerificationFailed 9

For any unknown errors, a LineSDKInternalErrorCodeUnknown error with code 0 is returned.

# Server response error

If a server error occurs and the LINE Platform returns an invalid HTTP status code, that code will be used as error code number. Such server error is under LineSDKServerErrorDomain and its userInfo property includes an underlying iOS system error object and the original response data. You can check them as below:

[apiClient getProfileWithCompletion:^(LineSDKProfile *profile, NSError *error) {
    if (error) {
        if ([error.domain isEqualToString:LineSDKServerErrorDomain]) {
            NSLog(@"Response Error. Status Code: %ld", error.code);
            NSLog(@"Underlying Error: %@", error.userInfo[NSUnderlyingErrorKey]);
            NSLog(@"Response Data: %@", error.userInfo[LineSDKServerErrorUserInfoKey]);
        }
    } else {
        // Success Logic.
    }
}];