fix(api-gateway): add grpc logs for internal errors

This commit is contained in:
Karol Sójko 2023-12-06 15:42:12 +01:00
parent 79ae07623f
commit 529795d393
No known key found for this signature in database
GPG key ID: C2F813669419D05F
3 changed files with 24 additions and 1 deletions

View file

@ -210,6 +210,7 @@ export class ContainerConfigLoader {
container.get<MapperInterface<SyncResponse, SyncResponseHttpRepresentation>>(
TYPES.Mapper_SyncResponseGRPCMapper,
),
container.get<winston.Logger>(TYPES.ApiGateway_Logger),
),
)
container

View file

@ -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(
@ -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)
}
})

View file

@ -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: {}',
)
})