Skip to content

Commit

Permalink
fix(api-gateway): add grpc logs for internal errors
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsojko committed Dec 6, 2023
1 parent 79ae076 commit 529795d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/api-gateway/src/Bootstrap/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class ContainerConfigLoader {
container.get<MapperInterface<SyncResponse, SyncResponseHttpRepresentation>>(
TYPES.Mapper_SyncResponseGRPCMapper,
),
container.get<winston.Logger>(TYPES.ApiGateway_Logger),
),
)
container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { MapperInterface } from '@standardnotes/domain-core'
import { Metadata } from '@grpc/grpc-js'

import { SyncResponseHttpRepresentation } from '../../Mapping/Sync/Http/SyncResponseHttpRepresentation'
import { Status } from '@grpc/grpc-js/build/src/constants'
import { Logger } from 'winston'

export class GRPCSyncingServerServiceProxy {
constructor(
private syncingClient: ISyncingClient,
private syncRequestGRPCMapper: MapperInterface<Record<string, unknown>, SyncRequest>,
private syncResponseGRPCMapper: MapperInterface<SyncResponse, SyncResponseHttpRepresentation>,
private logger: Logger,
) {}

async sync(
Expand Down Expand Up @@ -39,12 +42,31 @@ export class GRPCSyncingServerServiceProxy {
})
}

if (error.code === Status.INTERNAL) {
this.logger.error(
`[GRPCSyncingServerServiceProxy] Internal gRPC error: ${error.message}. Payload: ${JSON.stringify(
payload,
)}`,
)
}

return reject(error)
}

return resolve({ status: 200, data: this.syncResponseGRPCMapper.toProjection(syncResponse) })
})
} catch (error) {
if (
'code' in (error as Record<string, unknown>) &&
(error as Record<string, unknown>).code === Status.INTERNAL
) {
this.logger.error(
`[GRPCSyncingServerServiceProxy] Internal gRPC error: ${JSON.stringify(error)}. Payload: ${JSON.stringify(
payload,
)}`,
)
}

reject(error)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('SendMessageToClient', () => {

expect(result.isFailed()).toBe(true)
expect(result.getError()).toBe(
'Could not send message to connection connection-id for user 00000000-0000-0000-0000-000000000000. Error: error',
'Could not send message to connection connection-id for user 00000000-0000-0000-0000-000000000000. Error: {}',
)
})

Expand Down

0 comments on commit 529795d

Please sign in to comment.