Skip to content

Commit

Permalink
feat: Add error logging to forum post (#775)
Browse files Browse the repository at this point in the history
* feat: Add error logging to forum post

* fix: Use logger
  • Loading branch information
LautaroPetaccio committed Sep 23, 2024
1 parent 8fa8039 commit 678b4fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Forum/Forum.router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { server } from 'decentraland-server'
import { ILoggerComponent } from '@well-known-components/interfaces'
import { Router } from '../common/Router'
import { HTTPError, STATUS_CODES } from '../common/HTTPError'
import { getValidator } from '../utils/validator'
Expand All @@ -16,6 +17,7 @@ import { MAX_FORUM_ITEMS } from '../Item/utils'
import { Item } from '../Item'
import { Bridge } from '../ethereum/api/Bridge'
import { OwnableModel } from '../Ownable'
import { ExpressApp } from '../common/ExpressApp'
import { createPost } from './client'
import { ForumService } from './Forum.service'
import { ForumPost, forumPostSchema } from './Forum.types'
Expand All @@ -25,6 +27,12 @@ const validator = getValidator()
export class ForumRouter extends Router {
public service = new ForumService()
public collectionService = new CollectionService()
private logger: ILoggerComponent.ILogger

constructor(router: ExpressApp, logger: ILoggerComponent) {
super(router)
this.logger = logger.getLogger('ForumRouter')
}

private modelAuthorizationCheck = (
_: OwnableModel,
Expand Down Expand Up @@ -68,13 +76,21 @@ export class ForumRouter extends Router {
validate(forumPostJSON)

if (validate.errors) {
this.logger.error(
`Error trying to create the forum post for ${collectionId}, invalid schema: ${JSON.stringify(
validate.errors
)}`
)
throw new HTTPError('Invalid schema', validate.errors)
}
const forumPost: ForumPost = forumPostJSON as ForumPost

const collection = await Collection.findOne(collectionId)

if (collection.forum_link) {
this.logger.error(
`Error trying to create the forum post for ${collectionId}, forum post already exists`
)
throw new HTTPError('Forum post already exists', { id: collectionId })
}

Expand All @@ -99,6 +115,11 @@ export class ForumRouter extends Router {
return link
}
} catch (error) {
this.logger.error(
`Error trying to create the forum post for ${collectionId}: ${
isErrorWithMessage(error) ? error.message : 'Unknown'
}`
)
throw new HTTPError(
'Error creating forum post',
{ errors: isErrorWithMessage(error) ? error.message : 'Unknown' },
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ new CurationRouter(app).mount()
new CommitteeRouter(app).mount()
new ThirdPartyRouter(app).mount()
new RarityRouter(app).mount()
new ForumRouter(app).mount()
new ForumRouter(app, logs).mount()
new ManifestRouter(app).mount()
new DeploymentRouter(app).mount()
new S3Router(app).mount()
Expand Down

0 comments on commit 678b4fb

Please sign in to comment.