Skip to content

Commit

Permalink
refactor try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Nov 19, 2024
1 parent 066a9a6 commit f9ab64e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions teammapper-backend/src/map/controllers/maps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ export default class MapsController {

@Get(':id')
async findOne(@Param('id') mapId: string): Promise<IMmpClientMap | void> {
// If we update lastAccessed first, we guarantee that the exportMapToClient returns a fresh map that includes an up-to-date lastAccessed field
await this.mapsService.updateLastAccessed(mapId).catch((e: Error) => {
if (e instanceof MalformedUUIDError || e instanceof EntityNotFoundError) throw new NotFoundException()
})
try {
// If we update lastAccessed first, we guarantee that the exportMapToClient returns a fresh map that includes an up-to-date lastAccessed field
await this.mapsService.updateLastAccessed(mapId)
const map = await this.mapsService.exportMapToClient(mapId)
if (!map) throw new NotFoundException()

const map = await this.mapsService.exportMapToClient(mapId)
if (!map) throw new NotFoundException()
return map
} catch(e) {
if (e instanceof MalformedUUIDError || e instanceof EntityNotFoundError) throw new NotFoundException()
}

return map

}

@Delete(':id')
Expand Down

0 comments on commit f9ab64e

Please sign in to comment.