How to use the log/loginstance.LogInstance.error function in log

To help you get started, we’ve selected a few log examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github L-Leite / cso2-users-service / src / routes / users.ts View on Github external
if (isNaN(reqUserId)) {
      return res.status(400).end()
    }

    try {
      const user: User = await User.getUserById(reqUserId)

      // if the user isn't found
      if (user == null) {
        return res.status(404).end()
      }

      // return OK
      return res.status(200).json(user).end()
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / users.ts View on Github external
if (reqUsername == null) {
      return res.status(400).end()
    }

    try {
      const user: User = await User.getUserByName(reqUsername)

      // if the user isn't found
      if (user == null) {
        return res.status(404).end()
      }

      // return OK
      return res.status(200).json(user).end()
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
}
github L-Leite / cso2-users-service / src / routes / users.ts View on Github external
return res.status(400).end()
    }

    const MAX_COLUMN_LENGTH: number = 100

    if (colLength > MAX_COLUMN_LENGTH) {
      return res.status(413).end()
    }

    try {
      const users: User[] = await User.getAllUsers(colOffset, colLength)

      // return OK
      return res.status(200).json(users).end()
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / users.ts View on Github external
if (isNaN(reqUserId)) {
      return res.status(400).end()
    }

    try {
      const deleted: boolean = await User.removeUserById(reqUserId)

      if (deleted === true) {
        // return OK
        return res.status(200).end()
      } else {
        // if the user isn't found
        return res.status(404).end()
      }
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / users.ts View on Github external
return res.status(400).end()
    }

    try {
      const userExists: boolean = await User.isTaken(userName, playerName)

      if (userExists === true) {
        LogInstance.warn('Tried to create an existing user ' + userName + ' (' + playerName + ')')
        return res.status(409).end()
      }

      const newUser: User = await User.createUser(userName, playerName, password)

      return res.status(201).json(newUser).end()
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / sessions.ts View on Github external
const ownerId: number = Number(req.params.ownerId)

    if (isNaN(ownerId) === true) {
      return res.status(400).end()
    }

    try {
      const wasDeleted: boolean = await UserSession.deleteByUserId(ownerId)
      if (wasDeleted) {
        return res.status(200).end()
      } else {
        LogInstance.warn(`Tried to delete user's ${ownerId} session but failed.`)
        return res.status(404).end()
      }
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
}
github L-Leite / cso2-users-service / src / routes / sessions.ts View on Github external
if (isNaN(colOffset) === true
      || isNaN(colLength) === true) {
      return res.status(400).end()
    }

    const MAX_COLUMN_LENGTH: number = 100

    if (colLength > MAX_COLUMN_LENGTH) {
      return res.status(413).end()
    }

    try {
      const sessions: UserSession[] = await UserSession.getAll(colOffset, colLength)
      return res.status(200).json(sessions).end()
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / sessions.ts View on Github external
const ownerId: number = Number(req.params.ownerId)

    if (isNaN(ownerId)) {
      return res.status(400).end()
    }

    try {
      const session: UserSession = await UserSession.getByUserId(ownerId)

      if (session !== null) {
        return res.status(200).json(session).end()
      } else {
        return res.status(404).end()
      }
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / sessions.ts View on Github external
if (isNaN(ownerId) === true
      || req.body == null) {
      return res.status(400).end()
    }

    try {
      const wasUpdated: boolean = await UserSession.set(ownerId, req.body)

      if (wasUpdated) {
        return res.status(200).end()
      } else {
        return res.status(404).end()
      }
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }
github L-Leite / cso2-users-service / src / routes / sessions.ts View on Github external
private async onDeleteSessions(req: express.Request, res: express.Response): Promise {
    try {
      const wasDeleted: boolean = await UserSession.deleteAll()
      if (wasDeleted) {
        return res.status(200).end()
      } else {
        return res.status(500).end()
      }
    } catch (error) {
      LogInstance.error(error)
      return res.status(500).end()
    }
  }