diff --git a/src/client.ts b/src/client.ts index d37c0b2..47822a1 100644 --- a/src/client.ts +++ b/src/client.ts @@ -103,14 +103,16 @@ export class Client implements SmppSession { } this.session.bind_transceiver({ - system_id: this.username, password: this.password, + system_id: this._username, password: this._password, }, this.eventBindReply.bind(this)); }); return this.bindPromise; } connectAndBind(): Promise { - return this.connect().then(this.bind.bind(this)); + return this.connect().then(this.bind.bind(this), (error) => { + this.logger.log1(`Client-${this.id} connectAndBind failed: ${error}`); + }); } serialize(): string { @@ -160,10 +162,10 @@ export class Client implements SmppSession { this.eventEmitter.emit(Client.ClientEvents.ANY_PDU, pdu); } - private eventSessionError(): void { + private eventSessionError(pdu: any): void { this.logger.log1(`Client-${this.id} error on ${this._url}`); this.setStatus(ClientStatus.NOT_CONNECTED); - this.rejectPromises(); + this.rejectPromises(pdu); } private eventSessionClose(): void { @@ -183,17 +185,17 @@ export class Client implements SmppSession { this.logger.log1(`Client-${this.id} bind failed to ${this.url}`); this.setStatus(ClientStatus.CONNECTED); if (this.bindPromise) { - this.bindPromise.reject(); + this.bindPromise.reject(pdu); } } } - private rejectPromises(): void { + private rejectPromises(err?: any): void { if (this.connectPromise) { - this.connectPromise.reject(); + this.connectPromise.reject(err); } if (this.bindPromise) { - this.bindPromise.reject(); + this.bindPromise.reject(err); } } diff --git a/src/main.ts b/src/main.ts index f42cc27..fb432f6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,44 +22,11 @@ const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE // TODO: Add support for encodings // TODO: Implement some sort of metrics on frontend by counting the pdus -[ - 'debug', - 'log', - 'warn', - 'error' -].forEach((methodName: string) => { - // @ts-ignore - const originalLoggingMethod: object = console[methodName]; - // @ts-ignore - console[methodName] = (firstArgument, ...otherArguments) => { - // @ts-ignore - const originalPrepareStackTrace = Error.prepareStackTrace; - // @ts-ignore - Error.prepareStackTrace = (_, stack) => stack; - // @ts-ignore - const callee = new Error().stack[2]; - // @ts-ignore - Error.prepareStackTrace = originalPrepareStackTrace; - // @ts-ignore - const relativeFileName = path.relative(process.cwd(), callee.getFileName()); - // @ts-ignore - const prefix = `${relativeFileName}:${callee.getLineNumber()}:`; - // @ts-ignore - if (typeof firstArgument === 'string') { - // @ts-ignore - originalLoggingMethod(prefix + ' ' + firstArgument, ...otherArguments); - } else { - // @ts-ignore - originalLoggingMethod(prefix, firstArgument, ...otherArguments); - } - }; -}); - let logger = new Logger("main"); import {Client} from "./client"; -let client: Client = new Client(0, "smpp://localhost:7001", "test", "test"); +let client: Client = new Client(0, "smpp://localhost:7000", "test", "test"); client.connectAndBind().then(() => { console.log("POGGIES"); });