Skip to content

Commit

Permalink
fix(logging): log error and id of latest-entity-loader for Config doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sleidig committed Jul 2, 2024
1 parent 7bc360f commit 70d5b6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
32 changes: 17 additions & 15 deletions src/app/core/entity/latest-entity-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ export abstract class LatestEntityLoader<T extends Entity> {
* Do an initial load of the entity to be available through the `entityUpdated` property
* (without watching for continuous updates).
*/
loadOnce(): Promise<T | undefined> {
return this.entityMapper
.load(this.entityCtor, this.entityID)
.then((entity) => {
this.entityUpdated.next(entity);
return entity;
})
.catch((err) => {
if (err?.status !== HttpStatusCode.NotFound) {
this.logger.error(
`Loading entity "${this.entityCtor.ENTITY_TYPE}:${this.entityID}" failed: ${err} `,
);
}
return undefined;
});
async loadOnce(): Promise<T | undefined> {
try {
const entity = await this.entityMapper.load(
this.entityCtor,
this.entityID,
);
this.entityUpdated.next(entity);
return entity;
} catch (err) {
if (err?.status !== HttpStatusCode.NotFound) {
this.logger.error(
`Loading entity "${this.entityCtor.ENTITY_TYPE}:${this.entityID}" failed: ${this.entityID}`,
err,
);
}
return undefined;
}
}
}
5 changes: 3 additions & 2 deletions src/app/core/logging/logging.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export class LoggingService {
/**
* Log the message with "error" level - for unexpected critical events that cannot be handled and will affect functions.
* @param message
* @param context
*/
public error(message: any) {
this.log(message, LogLevel.ERROR);
public error(message: any, context?: any) {
this.log(message, LogLevel.ERROR, context);
}

/**
Expand Down

0 comments on commit 70d5b6b

Please sign in to comment.