Troubleshooting

This section will provide you with hints what to do if you’re having trouble with the library. If you cannot find an answer to your question, please contact us through the Kinvey Community Support forums.

Errors

On failure, all functions return an error object. This object holds the following properties:

  • name holds a generic error name. The name can be used to program against.
  • message contains a short, user-friendly, description of the error.
  • debug provides hints which might help you debug the error. This property is not always populated.

Not all errors thrown by the Kinvey API are represented in the list below. If an error is not supported it will be returned as an instance of Kinvey.Errors.KinveyError with the name property set to the name of the error and code set to the status code of the response returned from the Kinvey API. For a detailed list of possible errors returned by the backend please take a look at REST API Troubleshooting Guide.

The possible error types returned by the library is as follows:

ErrorDescription
Kinvey.Errors.ActiveUserErrorAn active user already exists.
Kinvey.Errors.APIVersionNotAvailableErrorThis API version is not available for your app. Please retry your request with a supported API version,
Kinvey.Errors.APIVersionNotImplementedErrorThis API version is not implemented. Please retry your request with a supported API version.
Kinvey.Errors.AppProblemErrorThere is a problem with this app backend that prevents execution of this operation. Please contact support@kinvey.com for assistance.
Kinvey.Errors.BadRequestErrorUnable to understand request.
Kinvey.Errors.BLErrorThe Business Logic script has an error. See debug message for details.
Kinvey.Errors.CORSDisabledErrorCross Origin Support is disabled for this application.
Kinvey.Errors.DuplicateEndUsersErrorMore than one user registered with this username for this application. Please contact support@kinvey.com for assistance.
Kinvey.Errors.FeatureUnavailableErrorRequested functionality is unavailable for the API version.
Kinvey.Errors.IncompleteRequestBodyErrorThe request body is either missing or incomplete.
Kinvey.Errors.IndirectCollectionAccessDisallowedErrorPlease use the appropriate API to access this collection for this app backend.
Kinvey.Errors.InsufficientCredentialsErrorThe credentials used to authenticate the request are not authorized to run this operation. Please retry the request with appropriate credentials.
Kinvey.Errors.InvalidCredentialsErrorInvalid credentials. Please retry the request with correct credentials.
Kinvey.Errors.InvalidIdentifierErrorOne of more identifier names in the request has an invalid format.
Kinvey.Errors.InvalidQuerySyntaxErrorThe query string in the request has an invalid syntax.
Kinvey.Errors.JSONParseErrorUnable to parse the JSON in the request.
Kinvey.Errors.KinveyInternalErrorRetryThe Kinvey server encountered an unexpected error. Please retry your request.
Kinvey.Errors.KinveyInternalErrorStopThe Kinvey server encountered an unexpected error. Please contact support@kinvey.com for assistance.
Kinvey.Errors.KinveyErrorAn error has occurred. This is a general error.
Kinvey.Errors.MissingQueryErrorThe request is missing a query string.
Kinvey.Errors.MissingRequestHeaderErrorThe request is missing a required header.
Kinvey.Errors.MissingRequestParameterErrorA required parameter is missing from the request.
Kinvey.Errors.MobileIdentityConnectErrorAn error has occurred with Mobile Identity Connect.
Kinvey.Errors.NoActiveUserErrorThere is not an active user.
Kinvey.Errors.NoNetworkConnectionErrorYou do not have a network connection.
Kinvey.Errors.NoResponseErrorNo response was provided for the request.
Kinvey.Errors.NotFoundErrorThe item was not found.
Kinvey.Errors.ParameterValueOutOfRangeErrorThe value specified for one of the request parameters is out of range.
Kinvey.Errors.PopupErrorAn error occurred with the popup.
Kinvey.Errors.QueryErrorAn error occurred with the query.
Kinvey.Errors.ServerErrorAn error occurred on the query.
Kinvey.Errors.SyncErrorAn error occurred during sync.
Kinvey.Errors.TimeoutErrorThe request timed out.
Kinvey.Errors.UserAlreadyExistsErrorThis username is already taken. Please retry your request with a different username.
Kinvey.Errors.WritesToCollectionDisallowedErrorThis collection is configured to disallow any modifications to an existing entity or creation of new entities.

Error Handling

To check for certain errors, we recommend to check if the error is an instanceof of the error object listed in the Errors section.

Example: Check if an error is an ActiveUserError

import { Component } from '@angular/core';
import { UserService, Errors } from 'kinvey-angular-sdk';

@Component()
export class UserComponent {
  constructor(private userService: UserService) { }

  async login(username: string, password: string) {
    try {
      const user = await this.userService.login(username, password);
      console.log(user);
    } catch (error) {
      if (error instanceof Errors.ActiveUserError) {
        // ...
      }
    }
  }
}

Example: Check if an error is a NotFoundError

import { Component } from '@angular/core';
import { DataStoreService, Errors } from 'kinvey-angular-sdk';

@Component()
export class DataStoreComponent {
  collection: any;

  constructor(datastoreService: DataStoreService) {
    this.collection = datastoreService.collection('<collection-name>');
  }

  findById(id: string) {
    this.collection.findById(id)
      .subscribe((entity) => {

      }, (error) => {
        if (error instanceof Errors.NotFoundError) {
          // ...
        }
      });
  }
}

Example: Check if an error is an ActiveUserError using the name property

import { Component } from '@angular/core';
import { UserService } from 'kinvey-angular-sdk';

@Component()
export class UserComponent {
  constructor(private userService: UserService) { }

  async login(username: string, password: string) {
    try {
      const user = await this.userService.login(username, password);
      console.log(user);
    } catch (error) {
      if (error.name === 'ActiveUserError') {
        // ...
      }
    }
  }
}

Example: Check if an error is a NotFoundError using the name property

import { Component } from '@angular/core';
import { DataStoreService } from 'kinvey-angular-sdk';

@Component()
export class DataStoreComponent {
  collection: any;

  constructor(datastoreService: DataStoreService) {
    this.collection = datastoreService.collection('<collection-name>');
  }

  findById(id: string) {
    this.collection.findById(id)
      .subscribe((entity) => {

      }, (error) => {
        // A NotFoundError could have a different name depending on the response
        // from the Kinvey API. It is recommended to use instanceof instead.
        if (error.name === 'NotFoundError') {
          // ...
        }
      });
  }
}

Exceptions

If you are using promises, any exceptions thrown inside the then handlers will be caught by the promise. What this means is that the following:

promise
  .then(() => {
    throw new Error('I am just an error.');
  });

Will not cause the exception to be visible in the log panel of your browser or IDE. This can lead to confusion as it seems that everything went fine, while in reality, the exception is thrown but not reported. To correctly deal with exceptions in promises, consider the approach below.

promise
  .then(() => {
    throw new Error('I am just an error.');
  })
  .catch(function(error) {
    // Check whether the error is an exception.
    if (error instanceof Error) {
      // error holds the Error thrown in the then handler above.
      // error.message === 'I am just an error.';
    }
  });

The error.message and error.stack properties will provide insight in what went wrong, and where.

Debugging

The library uses loglevel to log information. The default log level is Kinvey.Log.levels.ERROR. You can change the log level as show below.

import { Log } from 'kinvey-angular-sdk';

Log.setLevel(Log.levels.DEBUG);

From then on, the flow of every call you make will be printed out using loglevel. You might be able to identify the error by inspecting these messages. When contacting Kinvey, sending this log along will be of great help.

Tools

Mac users may wish to use WireShark or Charles.

Windows developers can use Fiddler which is the preferred tool at Kinvey.

There are a few open source and proprietary Java tools listed at Ask Ubuntu and one can always use Firebug through Firefox, or the Developer Tools through Chrome.