mirror of https://github.com/OpenVidu/openvidu.git
openvidu-node-client: Avoid multiple 'reject' calls in specific HttpErrors. Handling on errors in one place
parent
72b95741ca
commit
c0fa49af8d
|
@ -30,6 +30,16 @@ interface ObjMap<T> {
|
||||||
[s: string]: T;
|
[s: string]: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
interface HttpError {
|
||||||
|
message?: string;
|
||||||
|
response?: any;
|
||||||
|
request?: any;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
||||||
|
|
||||||
export class OpenVidu {
|
export class OpenVidu {
|
||||||
|
@ -155,6 +165,7 @@ export class OpenVidu {
|
||||||
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> {
|
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
let data;
|
let data;
|
||||||
|
let rejected = false;
|
||||||
|
|
||||||
if (param2 != null) {
|
if (param2 != null) {
|
||||||
if (typeof param2 === 'string') {
|
if (typeof param2 === 'string') {
|
||||||
|
@ -211,11 +222,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -232,6 +244,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public stopRecording(recordingId: string): Promise<Recording> {
|
public stopRecording(recordingId: string): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.post(this.host + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, undefined, {
|
.post(this.host + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, undefined, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -256,11 +269,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -277,6 +291,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public getRecording(recordingId: string): Promise<Recording> {
|
public getRecording(recordingId: string): Promise<Recording> {
|
||||||
return new Promise<Recording>((resolve, reject) => {
|
return new Promise<Recording>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.get(this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, {
|
.get(this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -290,11 +305,12 @@ 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()));
|
rejected = true
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -306,6 +322,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public listRecordings(): Promise<Recording[]> {
|
public listRecordings(): Promise<Recording[]> {
|
||||||
return new Promise<Recording[]>((resolve, reject) => {
|
return new Promise<Recording[]>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.get(this.host + OpenVidu.API_RECORDINGS, {
|
.get(this.host + OpenVidu.API_RECORDINGS, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -325,11 +342,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -346,6 +364,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public deleteRecording(recordingId: string): Promise<Error> {
|
public deleteRecording(recordingId: string): Promise<Error> {
|
||||||
return new Promise<Error>((resolve, reject) => {
|
return new Promise<Error>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.delete(this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, {
|
.delete(this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -359,11 +378,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -393,7 +413,7 @@ export class OpenVidu {
|
||||||
public startBroadcast(sessionId: string, broadcastUrl: string, properties?: RecordingProperties): Promise<void> {
|
public startBroadcast(sessionId: string, broadcastUrl: string, properties?: RecordingProperties): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
let data;
|
let data;
|
||||||
|
let rejected = false;
|
||||||
if (properties != undefined) {
|
if (properties != undefined) {
|
||||||
data = {
|
data = {
|
||||||
session: sessionId,
|
session: sessionId,
|
||||||
|
@ -436,11 +456,12 @@ export class OpenVidu {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -457,6 +478,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public stopBroadcast(sessionId: string): Promise<void> {
|
public stopBroadcast(sessionId: string): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
this.host + OpenVidu.API_BROADCAST_STOP,
|
this.host + OpenVidu.API_BROADCAST_STOP,
|
||||||
|
@ -484,11 +506,12 @@ export class OpenVidu {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -502,6 +525,7 @@ export class OpenVidu {
|
||||||
*/
|
*/
|
||||||
public fetch(): Promise<boolean> {
|
public fetch(): Promise<boolean> {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
return new Promise<boolean>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.get(this.host + OpenVidu.API_SESSIONS + '?pendingConnections=true', {
|
.get(this.host + OpenVidu.API_SESSIONS + '?pendingConnections=true', {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -548,11 +572,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -632,6 +657,7 @@ export class OpenVidu {
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Promise<{ changes: boolean; sessionChanges: ObjMap<boolean> }>((resolve, reject) => {
|
return new Promise<{ changes: boolean; sessionChanges: ObjMap<boolean> }>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.get(this.host + OpenVidu.API_SESSIONS + '?webRtcStats=true', {
|
.get(this.host + OpenVidu.API_SESSIONS + '?webRtcStats=true', {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -701,11 +727,12 @@ 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()));
|
rejected = true;
|
||||||
|
this.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.handleError(error, reject);
|
!rejected && this.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -735,8 +762,11 @@ export class OpenVidu {
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
handleError(error: AxiosError, reject: (reason?: any) => void) {
|
handleError(error: AxiosError | HttpError, reject: (reason?: any) => void) {
|
||||||
if (error.response) {
|
if (error.status) {
|
||||||
|
// Error returned by openvidu-server
|
||||||
|
reject(new Error(error.status.toString()));
|
||||||
|
} else 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(new Error(error.response.status.toString()));
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
|
|
|
@ -110,6 +110,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public generateToken(tokenOptions?: TokenOptions): Promise<string> {
|
public generateToken(tokenOptions?: TokenOptions): Promise<string> {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
session: this.sessionId,
|
session: this.sessionId,
|
||||||
role: !!tokenOptions && !!tokenOptions.role ? tokenOptions.role : null,
|
role: !!tokenOptions && !!tokenOptions.role ? tokenOptions.role : null,
|
||||||
|
@ -129,11 +130,12 @@ export class Session {
|
||||||
resolve(res.data.token);
|
resolve(res.data.token);
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -148,6 +150,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public createConnection(connectionProperties?: ConnectionProperties): Promise<Connection> {
|
public createConnection(connectionProperties?: ConnectionProperties): Promise<Connection> {
|
||||||
return new Promise<Connection>((resolve, reject) => {
|
return new Promise<Connection>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
type: !!connectionProperties && !!connectionProperties.type ? connectionProperties.type : null,
|
type: !!connectionProperties && !!connectionProperties.type ? connectionProperties.type : null,
|
||||||
data: !!connectionProperties && !!connectionProperties.data ? connectionProperties.data : null,
|
data: !!connectionProperties && !!connectionProperties.data ? connectionProperties.data : null,
|
||||||
|
@ -181,7 +184,8 @@ export class Session {
|
||||||
resolve(new Connection(res.data));
|
resolve(new Connection(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()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -198,6 +202,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public close(): Promise<void> {
|
public close(): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, {
|
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -213,11 +218,12 @@ export class Session {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -234,6 +240,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public fetch(): Promise<boolean> {
|
public fetch(): Promise<boolean> {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
return new Promise<boolean>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
|
const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
|
||||||
axios
|
axios
|
||||||
.get(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '?pendingConnections=true', {
|
.get(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '?pendingConnections=true', {
|
||||||
|
@ -252,11 +259,12 @@ export class Session {
|
||||||
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()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -280,6 +288,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public forceDisconnect(connection: string | Connection): Promise<void> {
|
public forceDisconnect(connection: string | Connection): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
|
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
|
||||||
axios
|
axios
|
||||||
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, {
|
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, {
|
||||||
|
@ -328,11 +337,12 @@ export class Session {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -354,6 +364,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public forceUnpublish(publisher: string | Publisher): Promise<void> {
|
public forceUnpublish(publisher: string | Publisher): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
|
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
|
||||||
axios
|
axios
|
||||||
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, {
|
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, {
|
||||||
|
@ -386,11 +397,12 @@ export class Session {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -422,6 +434,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public updateConnection(connectionId: string, connectionProperties: ConnectionProperties): Promise<Connection | undefined> {
|
public updateConnection(connectionId: string, connectionProperties: ConnectionProperties): Promise<Connection | undefined> {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
axios
|
axios
|
||||||
.patch(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, connectionProperties, {
|
.patch(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, connectionProperties, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -434,7 +447,8 @@ export class Session {
|
||||||
logger.log('Connection ' + connectionId + ' updated');
|
logger.log('Connection ' + connectionId + ' updated');
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Update the actual Connection object with the new options
|
// Update the actual Connection object with the new options
|
||||||
|
@ -453,7 +467,7 @@ export class Session {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -470,6 +484,7 @@ export class Session {
|
||||||
*/
|
*/
|
||||||
public getSessionHttp(): Promise<string> {
|
public getSessionHttp(): Promise<string> {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
let rejected = false;
|
||||||
if (!!this.sessionId) {
|
if (!!this.sessionId) {
|
||||||
resolve(this.sessionId);
|
resolve(this.sessionId);
|
||||||
}
|
}
|
||||||
|
@ -501,16 +516,19 @@ export class Session {
|
||||||
resolve(this.sessionId);
|
resolve(this.sessionId);
|
||||||
} else {
|
} else {
|
||||||
// ERROR response from openvidu-server. Resolve HTTP status
|
// ERROR response from openvidu-server. Resolve HTTP status
|
||||||
reject(new Error(res.status.toString()));
|
rejected = true;
|
||||||
|
this.ov.handleError(res, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (!!error.response && error.response.status === 409) {
|
if (!!error.response && error.response.status === 409) {
|
||||||
// 'customSessionId' already existed
|
// 'customSessionId' already existed
|
||||||
this.sessionId = this.properties.customSessionId;
|
this.sessionId = this.properties.customSessionId;
|
||||||
this.fetch().then(() => resolve(this.sessionId));
|
this.fetch()
|
||||||
|
.then(() => resolve(this.sessionId))
|
||||||
|
.catch((error) => !rejected && this.ov.handleError(error, reject));
|
||||||
} else {
|
} else {
|
||||||
this.ov.handleError(error, reject);
|
!rejected && this.ov.handleError(error, reject);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue