1
1
import { server } from 'decentraland-server'
2
+ import { ILoggerComponent } from '@well-known-components/interfaces'
2
3
import { Router } from '../common/Router'
3
4
import { HTTPError , STATUS_CODES } from '../common/HTTPError'
4
5
import { getValidator } from '../utils/validator'
@@ -16,6 +17,7 @@ import { MAX_FORUM_ITEMS } from '../Item/utils'
16
17
import { Item } from '../Item'
17
18
import { Bridge } from '../ethereum/api/Bridge'
18
19
import { OwnableModel } from '../Ownable'
20
+ import { ExpressApp } from '../common/ExpressApp'
19
21
import { createPost } from './client'
20
22
import { ForumService } from './Forum.service'
21
23
import { ForumPost , forumPostSchema } from './Forum.types'
@@ -25,6 +27,12 @@ const validator = getValidator()
25
27
export class ForumRouter extends Router {
26
28
public service = new ForumService ( )
27
29
public collectionService = new CollectionService ( )
30
+ private logger : ILoggerComponent . ILogger
31
+
32
+ constructor ( router : ExpressApp , logger : ILoggerComponent ) {
33
+ super ( router )
34
+ this . logger = logger . getLogger ( 'ForumRouter' )
35
+ }
28
36
29
37
private modelAuthorizationCheck = (
30
38
_ : OwnableModel ,
@@ -68,9 +76,10 @@ export class ForumRouter extends Router {
68
76
validate ( forumPostJSON )
69
77
70
78
if ( validate . errors ) {
71
- console . error (
72
- `Error trying to create the forum post for ${ collectionId } , invalid schema` ,
73
- validate . errors
79
+ this . logger . error (
80
+ `Error trying to create the forum post for ${ collectionId } , invalid schema: ${ JSON . stringify (
81
+ validate . errors
82
+ ) } `
74
83
)
75
84
throw new HTTPError ( 'Invalid schema' , validate . errors )
76
85
}
@@ -79,7 +88,7 @@ export class ForumRouter extends Router {
79
88
const collection = await Collection . findOne ( collectionId )
80
89
81
90
if ( collection . forum_link ) {
82
- console . error (
91
+ this . logger . error (
83
92
`Error trying to create the forum post for ${ collectionId } , forum post already exists`
84
93
)
85
94
throw new HTTPError ( 'Forum post already exists' , { id : collectionId } )
@@ -106,9 +115,10 @@ export class ForumRouter extends Router {
106
115
return link
107
116
}
108
117
} catch ( error ) {
109
- console . error (
110
- `Error trying to create the forum post for ${ collectionId } ` ,
111
- isErrorWithMessage ( error ) ? error . message : 'Unknown'
118
+ this . logger . error (
119
+ `Error trying to create the forum post for ${ collectionId } : ${
120
+ isErrorWithMessage ( error ) ? error . message : 'Unknown'
121
+ } `
112
122
)
113
123
throw new HTTPError (
114
124
'Error creating forum post' ,
0 commit comments