fix(api-gateway): add grpc logs for internal errors
This commit is contained in:
parent
79ae07623f
commit
529795d393
3 changed files with 24 additions and 1 deletions
|
@ -210,6 +210,7 @@ export class ContainerConfigLoader {
|
|||
container.get<MapperInterface<SyncResponse, SyncResponseHttpRepresentation>>(
|
||||
TYPES.Mapper_SyncResponseGRPCMapper,
|
||||
),
|
||||
container.get<winston.Logger>(TYPES.ApiGateway_Logger),
|
||||
),
|
||||
)
|
||||
container
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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: {}',
|
||||
)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue