Skip to content

Commit

Permalink
fix: log issue with non-json payload, #6
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierchow committed Mar 29, 2022
1 parent 47b78f7 commit 9638c92
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ app.connectMicroservice<MicroserviceOptions>({
import { Injectable } from '@nestjs/common';
import { EventPattern, Ctx, Payload } from '@nestjs/microservices';

@Injectable()
export class SomeService {
@Controller()
export class AppController {

@EventPattern({
topic: 'topic1',
Expand Down
16 changes: 8 additions & 8 deletions src/responder/inbound-message-deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ export class InboundMessageDeserializer implements ConsumerDeserializer {
private readonly logger = new Logger('InboundMessageIdentityDeserializer');

deserialize(value: any, options?: Record<string, any>): IncomingRequest {
let msg;
let json;

try {
msg = value.json();
} catch (err) {
msg = value;
}
json = value.json();
} catch (err) {}

this.logger.verbose(
`<<-- deserializing inbound message:\n
${JSON.stringify(msg)}
${(json && JSON.stringify(json)) || value.body}
\n\twith options: ${JSON.stringify(options)}`,
);

return {
id: msg.id,
data: msg,
id: value.id,
data: json || value.body,
pattern: options,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/responder/server-nsq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class ServerNsq extends Server implements CustomTransportStrategy {
`consumer reader failed to process message with error: ${err.message}, topic: ${topic}, channel: ${channel}`,
);
msg.requeue(consumerOptions.requeueDelay || DEFAULT_REQUEUE_DELAY);
return;
}

const wrappedErrObservable = source.pipe(
Expand Down
1 change: 1 addition & 0 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('AppController (e2e)', () => {
discardCalled = mockDiscardHdlr.mock.calls.length;
}
expect(discardCalled).toBe(1);
mockDiscardHdlr.mockClear();
}, 10000);

it('should be able to dispatch event', async () => {
Expand Down

0 comments on commit 9638c92

Please sign in to comment.