Skip to content

Commit 4a6f1f2

Browse files
authored
Merge pull request #6 from Vatis-Tech/refactor/VAT-382
VAT-382: add error handling
2 parents a3b4f81 + 7b5e4e7 commit 4a6f1f2

16 files changed

+198
-52
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ No fixes were made.
5151

5252
Each time you add new changes to this file, please add them bellow this line - i.e. between the [insertion](#insterion) section and the last version added.
5353

54+
## [1.1.0] - 2022-04-04
55+
56+
### Added
57+
58+
- Added `errorHandler` prop for the client: this will be called now, instead of `console.error` and `throw` of the errors
59+
60+
### Changed
61+
62+
- Changed the way errors are handled: no error is consoled or thrown anymore, they are sent through the `errorHandler` prop so that the user/client can catch them and action accordingly
63+
64+
### Removed
65+
66+
- `const errorMessage = ...`
67+
- `console.error(errorMessage);`
68+
- `throw errorMessage;`
69+
70+
### Fixed
71+
72+
No fixes were made.
73+
5474
## [1.0.0] - 2022-03-28
5575

5676
### Added

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @vatis-tech/asr-client-js
22

3-
![version](https://img.shields.io/badge/version-1.0.0-blue.svg)
3+
![version](https://img.shields.io/badge/version-1.1.0-blue.svg)
44
![license](https://img.shields.io/badge/license-MIT-blue.svg)
55
![GitHub issues open](https://img.shields.io/github/issues/Vatis-Tech/asr-client-js.svg)
66
![GitHub issues closed](https://img.shields.io/github/issues-closed-raw/Vatis-Tech/asr-client-js.svg)
@@ -180,6 +180,10 @@ If `log` prop is set to `true` and the `logger` prop is not set, or is not a fun
180180

181181
This is a **Function** that will be called upon successful destruction;
182182

183+
### `errorHandler`
184+
185+
This is a **Function** that will be called upon errors;
186+
183187
### `host`
184188

185189
This is the host for generating a key. It defaults to "https://vatis.tech/".
@@ -224,8 +228,8 @@ After calling the `pause` method, you can call this one to resume recording.
224228

225229
We officially support the latest versions of the following browsers:
226230

227-
| Chrome | Firefox | Safari | Safari | Edge |
228-
| :-----------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------: |
231+
| Chrome | Firefox | Safari | Safari | Edge |
232+
| :------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |
229233
| <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/chrome.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/firefox.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/safari.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/safari-technology-preview.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/edge.png?raw=true" width="48" height="48"> |
230234

231235
## Contributing

dist/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ No fixes were made.
5151

5252
Each time you add new changes to this file, please add them bellow this line - i.e. between the [insertion](#insterion) section and the last version added.
5353

54+
## [1.1.0] - 2022-04-04
55+
56+
### Added
57+
58+
- Added `errorHandler` prop for the client: this will be called now, instead of `console.error` and `throw` of the errors
59+
60+
### Changed
61+
62+
- Changed the way errors are handled: no error is consoled or thrown anymore, they are sent through the `errorHandler` prop so that the user/client can catch them and action accordingly
63+
64+
### Removed
65+
66+
- `const errorMessage = ...`
67+
- `console.error(errorMessage);`
68+
- `throw errorMessage;`
69+
70+
### Fixed
71+
72+
No fixes were made.
73+
5474
## [1.0.0] - 2022-03-28
5575

5676
### Added

dist/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @vatis-tech/asr-client-js
22

3-
![version](https://img.shields.io/badge/version-1.0.0-blue.svg)
3+
![version](https://img.shields.io/badge/version-1.1.0-blue.svg)
44
![license](https://img.shields.io/badge/license-MIT-blue.svg)
55
![GitHub issues open](https://img.shields.io/github/issues/Vatis-Tech/asr-client-js.svg)
66
![GitHub issues closed](https://img.shields.io/github/issues-closed-raw/Vatis-Tech/asr-client-js.svg)
@@ -180,6 +180,10 @@ If `log` prop is set to `true` and the `logger` prop is not set, or is not a fun
180180

181181
This is a **Function** that will be called upon successful destruction;
182182

183+
### `errorHandler`
184+
185+
This is a **Function** that will be called upon errors;
186+
183187
### `host`
184188

185189
This is the host for generating a key. It defaults to "https://vatis.tech/".
@@ -224,8 +228,8 @@ After calling the `pause` method, you can call this one to resume recording.
224228

225229
We officially support the latest versions of the following browsers:
226230

227-
| Chrome | Firefox | Safari | Safari | Edge |
228-
| :-----------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------: |
231+
| Chrome | Firefox | Safari | Safari | Edge |
232+
| :------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |
229233
| <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/chrome.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/firefox.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/safari.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/safari-technology-preview.png?raw=true" width="48" height="48"> | <img src="https://github.com/Vatis-Tech/asr-client-js/blob/main/github-assets/logos/edge.png?raw=true" width="48" height="48"> |
230234

231235
## Contributing

dist/components/ApiKeyGenerator.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var ApiKeyGenerator = /*#__PURE__*/function () {
1818
var apiUrl = _ref.apiUrl,
1919
responseCallback = _ref.responseCallback,
2020
apiKey = _ref.apiKey,
21-
logger = _ref.logger;
21+
logger = _ref.logger,
22+
errorHandler = _ref.errorHandler;
2223

2324
_classCallCheck(this, ApiKeyGenerator);
2425

@@ -36,6 +37,9 @@ var ApiKeyGenerator = /*#__PURE__*/function () {
3637

3738
_defineProperty(this, "logger", void 0);
3839

40+
_defineProperty(this, "errorHandler", void 0);
41+
42+
this.errorHandler = errorHandler;
3943
this.logger = logger;
4044
this.logger({
4145
currentState: "@vatis-tech/asr-client-js: Instantianting the \"ApiKeyGenerator\" plugin.",
@@ -63,13 +67,20 @@ var ApiKeyGenerator = /*#__PURE__*/function () {
6367
}, {
6468
key: "onError",
6569
value: function onError(e) {
66-
var errorMessage = "Could not initilize the API KEY.";
67-
console.error(errorMessage);
68-
throw errorMessage;
70+
this.logger({
71+
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"ApiKeyGenerator\" plugin.",
72+
description: "@vatis-tech/asr-client-js: " + e
73+
});
74+
this.errorHandler(e);
6975
}
7076
}, {
7177
key: "onLoad",
7278
value: function onLoad() {
79+
if (this.xmlHttp.status !== 200) {
80+
this.onError(JSON.parse(this.xmlHttp.responseText));
81+
return;
82+
}
83+
7384
this.logger({
7485
currentState: "@vatis-tech/asr-client-js: Initialized the \"ApiKeyGenerator\" plugin.",
7586
description: "@vatis-tech/asr-client-js: A valid key was received from the Vatis Tech API, in order to use the LIVE ASR service."

dist/components/InstanceReservation.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var generateReservationUrl = _index["default"].generateReservationUrl;
2222
var InstanceReservation = /*#__PURE__*/function () {
2323
function InstanceReservation(_ref) {
2424
var responseCallback = _ref.responseCallback,
25-
logger = _ref.logger;
25+
logger = _ref.logger,
26+
errorHandler = _ref.errorHandler;
2627

2728
_classCallCheck(this, InstanceReservation);
2829

@@ -40,6 +41,9 @@ var InstanceReservation = /*#__PURE__*/function () {
4041

4142
_defineProperty(this, "logger", void 0);
4243

44+
_defineProperty(this, "errorHandler", void 0);
45+
46+
this.errorHandler = errorHandler;
4347
this.logger = logger;
4448
this.logger({
4549
currentState: "@vatis-tech/asr-client-js: Instantianting the \"InstanceReservation\" plugin.",
@@ -71,13 +75,20 @@ var InstanceReservation = /*#__PURE__*/function () {
7175
}, {
7276
key: "onError",
7377
value: function onError(e) {
74-
var errorMessage = "Could not reserve a live asr instance.";
75-
console.error(errorMessage);
76-
throw errorMessage;
78+
this.logger({
79+
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"InstanceReservation\" plugin.",
80+
description: "@vatis-tech/asr-client-js: " + e
81+
});
82+
this.errorHandler(e);
7783
}
7884
}, {
7985
key: "onLoad",
8086
value: function onLoad() {
87+
if (this.xmlHttp.status !== 200) {
88+
this.onError(JSON.parse(this.xmlHttp.responseText));
89+
return;
90+
}
91+
8192
this.logger({
8293
currentState: "@vatis-tech/asr-client-js: Initialized the \"InstanceReservation\" plugin.",
8394
description: "@vatis-tech/asr-client-js: A live asr instance has been reserved."

dist/components/MicrophoneGenerator.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var MicrophoneGenerator = /*#__PURE__*/function () {
3131
function MicrophoneGenerator(_ref) {
3232
var onDataCallback = _ref.onDataCallback,
3333
logger = _ref.logger,
34-
microphoneTimeslice = _ref.microphoneTimeslice;
34+
microphoneTimeslice = _ref.microphoneTimeslice,
35+
errorHandler = _ref.errorHandler;
3536

3637
_classCallCheck(this, MicrophoneGenerator);
3738

@@ -47,6 +48,9 @@ var MicrophoneGenerator = /*#__PURE__*/function () {
4748

4849
_defineProperty(this, "microphoneTimeslice", void 0);
4950

51+
_defineProperty(this, "errorHandler", void 0);
52+
53+
this.errorHandler = errorHandler;
5054
this.logger = logger;
5155
this.logger({
5256
currentState: "@vatis-tech/asr-client-js: Instantianting the \"MicrophoneGenerator\" plugin.",
@@ -165,9 +169,12 @@ var MicrophoneGenerator = /*#__PURE__*/function () {
165169
description: "@vatis-tech/asr-client-js: The MicrophoneGenerator was successful into getting user's microphone, and will start sending data each ".concat(_this.microphoneTimeslice, " miliseconds.")
166170
});
167171
})["catch"](function (err) {
168-
var errorMessage = "Could not initilize the microphone stream with error: " + err;
169-
console.error(errorMessage);
170-
throw errorMessage;
172+
_this.logger({
173+
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"MicrophoneGenerator\" plugin.",
174+
description: "@vatis-tech/asr-client-js: " + err
175+
});
176+
177+
_this.errorHandler(err);
171178
});
172179

173180
case 3:

dist/components/SocketIOClientGenerator.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ var SocketIOClientGenerator = /*#__PURE__*/function () {
3939
destroyVTC = _ref.destroyVTC,
4040
frameLength = _ref.frameLength,
4141
frameOverlap = _ref.frameOverlap,
42-
bufferOffset = _ref.bufferOffset;
42+
bufferOffset = _ref.bufferOffset,
43+
errorHandler = _ref.errorHandler;
4344

4445
_classCallCheck(this, SocketIOClientGenerator);
4546

@@ -63,6 +64,9 @@ var SocketIOClientGenerator = /*#__PURE__*/function () {
6364

6465
_defineProperty(this, "bufferOffset", void 0);
6566

67+
_defineProperty(this, "errorHandler", void 0);
68+
69+
this.errorHandler = errorHandler;
6670
this.logger = logger;
6771
this.logger({
6872
currentState: "@vatis-tech/asr-client-js: Instantianting the \"SocketIOClientGenerator\" plugin.",
@@ -125,9 +129,12 @@ var SocketIOClientGenerator = /*#__PURE__*/function () {
125129
});
126130
});
127131
this.socketRef.on("connect_error", function (error) {
128-
var errorMessage = 'Could not initilize the "socket.io-client" with error: ' + error;
129-
console.error(errorMessage);
130-
throw errorMessage;
132+
_this.logger({
133+
currentState: "@vatis-tech/asr-client-js: Could not initilize the \"SocketIOClientGenerator\" plugin.",
134+
description: "@vatis-tech/asr-client-js: " + error
135+
});
136+
137+
_this.errorHandler(error);
131138
});
132139
this.socketRef.on(SOCKET_IO_CLIENT_RESULT_PATH, function (args) {
133140
_this.onAsrResultCallback(args);

0 commit comments

Comments
 (0)