openvidu-node-client: Updated rejected responses and dependencies

Old promises rejections return unusable responses to the client. Now they return the status code
pull/730/head
csantosm 2022-05-26 13:42:58 +02:00
parent 75f4c6497f
commit df7bd5f202
3 changed files with 906 additions and 792 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,37 @@
{ {
"author": "OpenVidu", "author": "OpenVidu",
"dependencies": { "dependencies": {
"axios": "0.21.4", "axios": "0.27.2",
"buffer": "6.0.3" "buffer": "6.0.3"
}, },
"description": "OpenVidu Node Client", "description": "OpenVidu Node Client",
"devDependencies": { "devDependencies": {
"@types/node": "14.14.37", "@types/node": "17.0.35",
"grunt": "1.3.0", "grunt": "1.5.3",
"grunt-cli": "1.4.2", "grunt-cli": "1.4.3",
"grunt-contrib-copy": "1.0.0", "grunt-contrib-copy": "1.0.0",
"grunt-contrib-sass": "2.0.0", "grunt-contrib-sass": "2.0.0",
"grunt-contrib-uglify": "5.0.1", "grunt-contrib-uglify": "5.2.1",
"grunt-contrib-watch": "1.1.0", "grunt-contrib-watch": "1.1.0",
"grunt-postcss": "0.9.0", "grunt-postcss": "0.9.0",
"grunt-string-replace": "1.3.1", "grunt-string-replace": "1.3.1",
"grunt-ts": "6.0.0-beta.22", "grunt-ts": "6.0.0-beta.22",
"ts-node": "9.1.1", "ts-node": "10.8.0",
"tslint": "6.1.3", "tslint": "6.1.3",
"typedoc": "0.19.2", "typedoc": "0.22.15",
"typescript": "3.8.3" "typescript": "4.0.8"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"main": "lib/index.js", "main": "lib/index.js",
"name": "openvidu-node-client", "name": "openvidu-node-client",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/OpenVidu/openvidu" "url": "git://github.com/OpenVidu/openvidu"
}, },
"scripts": { "scripts": {
"build": "./node_modules/typescript/bin/tsc", "build": "./node_modules/typescript/bin/tsc",
"docs": "./generate-docs.sh" "docs": "./generate-docs.sh"
}, },
"typings": "lib/index.d.ts", "typings": "lib/index.d.ts",
"version": "2.22.0" "version": "2.22.0"
} }

View File

@ -89,7 +89,7 @@ export class OpenVidu {
/** /**
* @param hostname URL where your instance of OpenVidu Server is up an running. * @param hostname URL where your instance of OpenVidu Server is up an running.
* It must be the full URL (e.g. `https://12.34.56.78:1234/`) * It must be the full URL (e.g. `https://12.34.56.78:1234/`)
* *
* @param secret Secret used on OpenVidu Server initialization * @param secret Secret used on OpenVidu Server initialization
*/ */
constructor(private hostname: string, secret: string) { constructor(private hostname: string, secret: string) {
@ -101,9 +101,9 @@ export class OpenVidu {
* Creates an OpenVidu session. The session identifier will be available at property [[Session.sessionId]] * Creates an OpenVidu session. The session identifier will be available at property [[Session.sessionId]]
* *
* @returns A Promise that is resolved to the [[Session]] if success and rejected with an Error object if not. * @returns A Promise that is resolved to the [[Session]] if success and rejected with an Error object if not.
* This Error object has as `message` property with a status code carrying a specific meaning * This Error object has as `message` property with a status code carrying a specific meaning
* (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-start)). * (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-start)).
* *
* This method will never return an Error with status `409`. If a session with the same `customSessionId` already * This method will never return an Error with status `409`. If a session with the same `customSessionId` already
* exists in OpenVidu Server, a [[Session.fetch]] operation is performed in the background and the updated Session * exists in OpenVidu Server, a [[Session.fetch]] operation is performed in the background and the updated Session
* object is returned. * object is returned.
@ -134,7 +134,7 @@ export class OpenVidu {
* @param properties Custom RecordingProperties to apply to this Recording. This will override the global default values set to the Session with [[SessionProperties.defaultRecordingProperties]] * @param properties Custom RecordingProperties to apply to this Recording. This will override the global default values set to the Session with [[SessionProperties.defaultRecordingProperties]]
* *
* @returns A Promise that is resolved to the [[Recording]] if it successfully started (the recording can be stopped with guarantees) and rejected with an Error * @returns A Promise that is resolved to the [[Recording]] if it successfully started (the recording can be stopped with guarantees) and rejected with an Error
* object if not. This Error object has as `message` property with a status code carrying a specific meaning * object if not. This Error object has as `message` property with a status code carrying a specific meaning
* (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-start)). * (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-start)).
*/ */
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> { public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> {
@ -196,7 +196,7 @@ export class OpenVidu {
resolve(r); resolve(r);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -210,7 +210,7 @@ export class OpenVidu {
* @param recordingId The `id` property of the [[Recording]] you want to stop * @param recordingId The `id` property of the [[Recording]] you want to stop
* *
* @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not. * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not.
* This Error object has as `message` property with a status code carrying a specific meaning * This Error object has as `message` property with a status code carrying a specific meaning
* (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-stop)). * (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-stop)).
*/ */
public stopRecording(recordingId: string): Promise<Recording> { public stopRecording(recordingId: string): Promise<Recording> {
@ -239,7 +239,7 @@ export class OpenVidu {
resolve(r); resolve(r);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -253,7 +253,7 @@ export class OpenVidu {
* @param recordingId The `id` property of the [[Recording]] you want to retrieve * @param recordingId The `id` property of the [[Recording]] you want to retrieve
* *
* @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not. * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not.
* This Error object has as `message` property with a status code carrying a specific meaning * This Error object has as `message` property with a status code carrying a specific meaning
* (see [REST API](/en/stable/reference-docs/REST-API/#get-recording)). * (see [REST API](/en/stable/reference-docs/REST-API/#get-recording)).
*/ */
public getRecording(recordingId: string): Promise<Recording> { public getRecording(recordingId: string): Promise<Recording> {
@ -274,7 +274,7 @@ export class OpenVidu {
resolve(new Recording(res.data)); resolve(new Recording(res.data));
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -311,7 +311,7 @@ export class OpenVidu {
resolve(recordingArray); resolve(recordingArray);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -325,7 +325,7 @@ export class OpenVidu {
* @param recordingId * @param recordingId
* *
* @returns A Promise that is resolved if the Recording was successfully deleted and rejected with an Error object if not. * @returns A Promise that is resolved if the Recording was successfully deleted and rejected with an Error object if not.
* This Error object has as `message` property with a status code carrying a specific meaning * This Error object has as `message` property with a status code carrying a specific meaning
* (see [REST API](/en/stable/reference-docs/REST-API/#delete-recording)). * (see [REST API](/en/stable/reference-docs/REST-API/#delete-recording)).
*/ */
public deleteRecording(recordingId: string): Promise<Error> { public deleteRecording(recordingId: string): Promise<Error> {
@ -346,7 +346,7 @@ export class OpenVidu {
resolve(undefined); resolve(undefined);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -416,7 +416,7 @@ export class OpenVidu {
resolve(hasChanged); resolve(hasChanged);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -573,7 +573,7 @@ export class OpenVidu {
resolve({ changes: globalChanges, sessionChanges }); resolve({ changes: globalChanges, sessionChanges });
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString())); reject(res.status);
} }
}).catch(error => { }).catch(error => {
this.handleError(error, reject); this.handleError(error, reject);
@ -602,15 +602,15 @@ export class OpenVidu {
handleError(error: AxiosError, reject: (reason?: any) => void) { handleError(error: AxiosError, reject: (reason?: any) => void) {
if (error.response) { if (error.response) {
// The request was made and the server responded with a status code (not 2xx) // The request was made and the server responded with a status code (not 2xx)
reject(new Error(error.response.status.toString())); reject(error.response.status);
} else if (error.request) { } else if (error.request) {
// The request was made but no response was received // The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js // http.ClientRequest in node.js
reject(new Error(error.request)); reject(error.request);
} else { } else {
// Something happened in setting up the request that triggered an Error // Something happened in setting up the request that triggered an Error
reject(new Error(error.message)); reject(error.message);
} }
} }