Error analysis during development with HomeServer URL endpoints
Content
1.
Introduction
2.
Notes on client behaviour
3.
General information
4.
Notes on using the URL endpoints JavaScript API

## 1.Introduction

This article provides hints for debugging and error analysis during development with the HomeServer URL-Endpoints interface.

## 2.Notes on client behaviour

When sending data, especially with large amounts of data, the following must be observed:
The client itself is responsible for answering the pings from the HS according to the web socket protocol!
If the client does not answer the ping of the HS within 10 seconds, the HS will close the web socket connection!

## 3.General information

- Evaluate status codes:
  Every message from the client via HTTP and WebSocket is answered by the HomeServer/FacilityServer. If a message is not answered, there is probably a fundamental problem with the communication.
  The response from HS/FS contains a status code. This provides information on whether the HS/FS can evaluate and process the client's message. If this is not the case, the HS/FS returns a status code that is not equal to 0. A list of the possible status codes with their respective meaning can be found in the documentation HomeServer URL Endpoints.
  A message to the HS/FS can only be considered as delivered when the HS/FS replies with status code 0. However, this does not mean that the method possibly specified in the message (e.g. setting a communication object to a value or starting a sequence) has already been executed by the HS/FS.
- Information on the debug page:
  - Area Exceptions:
    - If the HS/FS returns a status code unequal to 0 to the client, one or more exceptions are listed here, which can provide a hint to the error in the message of the client.
  - Area WS:
    - In this area various statistical information about the WebSocket interface of the HS/FS is provided. Among other things the currently active connections are displayed.

## 4.Notes on using the URL endpoints JavaScript API

- Use the debugger of the browser:
  In almost all modern browsers JavaScript debuggers are available either by default (Chrome and Internet Explorer) or as a plugin (Firebug for Firefox and Safari).
- Evaluate the error parameter in the callback methods:
  If a callback is passed to a method of the API, it always has an error parameter (err) in its signature. If this is set when the callback method is called (i.e. not undefined), the code must react accordingly.
- Example:

  `var connectionOptions = {"host": homeserverIp, "port": homeserverPort}; var homeServerConnection = HomeServerConnector.createConnection(name, password, connectionOptions); var camArchCorridor = homeServerConnection.getCameraArchive('SC@camArchCorridor'); camArchCorridor.getPicture(userPictureId, function(err, pictureId, dataUrl){ if(err){ console.error("camArchCorridor.getPicture() failed!", err); showErrorToUser("Kamerabild konnte nicht abgerufen werden.") return; } showImage(pictureId, dataUrl); });`

- Use the source code of the URL endpoints JavaScript API:
  In order to evaluate errors that occur within the API or to trace or debug the processes of the API, the source code of the API can be used/integrated instead of the hs.min.js version optimised for productive use. The file hs.src.js is located in the directory URL-Endpoints\JS\API\src.