Skip to main content

SDK Error Handling

Handling Errors

The FeedFM SDK provides multiple mechanisms for error reporting. It is essential to implement proper error handling to ensure your application behaves reliably and predictably.

Return Values

Some methods in the SDK return a BOOL value to indicate immediate success or failure. These methods may initiate a long-running asynchronous operation, and the returned value only signifies whether that operation was successfully started.

Always handle the return value appropriately, and refer to the SDK documentation to understand what errors may occur and under which conditions.

Example:

const BOOL result = [[FMAudioPlayer sharedPlayer] play];
if (result == NO) {
// Could not initiate play operation
}

Completion Handlers

Methods that accept completion handlers use blocks to deliver the result of an operation. Completion handlers allow you to clearly associate outcomes with the method calls that triggered them.

If a method is available in both synchronous and asynchronous variants (i.e., with and without a completion handler), it is strongly recommended to use the version with a completion handler to avoid missing potential errors reported by the SDK.

Example:

[[FMAudioPlayer sharedPlayer] likeWithCompletion:^(NSError * _Nullable error) {
if (error) {
FMLogError(@"Error occured while liking: %@", error.localizedDescription);
}
}];

FMAudioPlayerDelegate

Some errors are not directly associated with specific user-initiated method calls. These can occur during the SDK’s background operations—for example, network failures or server-side issues while streaming audio.

To be notified of such events, implement the FMAudioPlayerDelegate protocol.

Example:

[FMAudioPlayer sharedPlayer].delegate = self;

...

- (void)audioPlayerDidReceiveError:(nonnull NSError*)error {
NSLog(@"FMAudioPlayer received error: %@", error);
}

NSNotifications (Deprecated)

In previous versions of the SDK, status updates and error messages were communicated primarily through NSNotification objects. This approach is now deprecated and has been replaced by the mechanisms described above.

For reference or backward compatibility, you can review the notifications emitted by the SDK in the FMAudioPlayer.h header file.

Errors

The SDK reports errors using instances of the FeedFMError class. For a comprehensive list of possible error codes and descriptions, refer to the FeedFMError.h header file.

In some cases, the FeedFMError object may include an underlying error, which can provide additional context and insight into the cause of the failure.

NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];
if (underlyingError) {
NSLog(@"Underlying error: %@", underlyingError);
}

List of Error Codes

Error CodeDescription
FeedFMErrorCodeNetworkFailureNetwork connection failed. Please check your internet connection and try again.
FeedFMErrorCodeInvalidRequestThe request was malformed or contained invalid parameters.
FeedFMErrorCodeInvalidResponseReceived an invalid response from the server.
FeedFMErrorCodeUnauthorizedUnauthorized access. Check your credentials or authentication token.
FeedFMErrorCodeInvalidRegionInvalid region, service is not available in your current geographic region.
FeedFMErrorCodeUnexpectedErrorAn unexpected error occurred.
FeedFMErrorCodeClientCreationFailedFailed to create the client.
FeedFMErrorCodeSessionNotAvailableSession is not available. Ensure that a session is created before making this request.
FeedFMErrorCodeSessionRequestErrorAn error occurred while sending a request to the session.
FeedFMErrorCodeSessionCreationFailedFailed to create a session.
FeedFMErrorCodeSessionUpdateFailedFailed to update the session.
FeedFMErrorCodeSkipNotAllowedForSimulcastSkipping is not allowed for simulcast stations.
FeedFMErrorCodeSkipAlreadyInProgressSkip operation is already in progress.
FeedFMErrorCodeLikeNoActiveStationNo active station to like.
FeedFMErrorCodeLikeNoActiveItemNo active item to like.
FeedFMErrorCodeLikeNotAllowedLike operation is not allowed.
FeedFMErrorCodeDislikeNoActiveStationNo active station to dislike.
FeedFMErrorCodeDislikeNoActiveItemNo active item to dislike.
FeedFMErrorCodeDislikeNotAllowedDislike operation is not allowed.
FeedFMErrorCodeUnlikeNoActiveStationNo active station to unlike.
FeedFMErrorCodeUnlikeNoActiveItemNo active item to unlike.
FeedFMErrorCodeUnlikeNotAllowedUnlike operation is not allowed.
FeedFMErrorCodePlayerNotInitializedAudio player is not initialized.
FeedFMErrorCodePlayerPlaybackUnavailablePlayback is unavailable.
FeedFMErrorCodePlayerNoItemsToLoadNo audio items are available to load.
FeedFMErrorCodePlayerCouldNotLoadItemCould not load the requested item.
FeedFMErrorCodePlayerNoMoreMusicUnable to retrieve more music for the current station/birate/codec configuration.
FeedFMErrorCodeUnknownAn unknown error occurred. Please try again or contact support if the issue continues.