Skip to content

Commit

Permalink
Merge pull request #583 from oceanprotocol/improve-error-logs
Browse files Browse the repository at this point in the history
Logging all errors
  • Loading branch information
jamiehewitt15 authored Aug 12, 2024
2 parents 0c03f69 + ef7bc51 commit 77ff139
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Indexer/crawlerThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ async function retryCrawlerWithDelay(
return retryCrawlerWithDelay(blockchain, retryInterval)
}
} catch (err) {
INDEXER_LOGGER.error(`Error starting crawler: ${err.message}`)
return false
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/core/handler/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export class GetDdoHandler extends Handler {
status: { httpStatus: 200 }
}
} catch (error) {
CORE_LOGGER.error(`Get DDO error: ${error}`)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand Down
1 change: 1 addition & 0 deletions src/components/core/handler/downloadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export class DownloadHandler extends Handler {
}
provider = blockchain.getProvider()
} catch (e) {
CORE_LOGGER.error('Download JsonRpcProvider ERROR: ' + e.message)
return {
stream: null,
status: {
Expand Down
3 changes: 3 additions & 0 deletions src/components/core/handler/encryptHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
buildInvalidRequestMessage,
validateCommandParameters
} from '../../httpRoutes/validateCommands.js'
import { CORE_LOGGER } from '../../../utils/logging/common.js'

// for encryption
export const SUPPORTED_ENCRYPTION_ENCODINGS = ['string', 'base58']
Expand Down Expand Up @@ -70,6 +71,7 @@ export class EncryptHandler extends Handler {
status: { httpStatus: 200 }
}
} catch (error) {
CORE_LOGGER.error(`Error while encrypting data: ${error} `)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand Down Expand Up @@ -130,6 +132,7 @@ export class EncryptFileHandler extends Handler {
}
}
} catch (error) {
CORE_LOGGER.error(`Error while encrypting file: ${error} `)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand Down
3 changes: 3 additions & 0 deletions src/components/core/handler/queryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
buildInvalidParametersResponse,
validateCommandParameters
} from '../../httpRoutes/validateCommands.js'
import { CORE_LOGGER } from '../../../utils/logging/common.js'

export class QueryHandler extends Handler {
validate(command: QueryCommand): ValidateParams {
Expand All @@ -28,6 +29,7 @@ export class QueryHandler extends Handler {
status: { httpStatus: 200 }
}
} catch (error) {
CORE_LOGGER.error(`Error in QueryHandler: ${error.message}`)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand All @@ -49,6 +51,7 @@ export class QueryDdoStateHandler extends QueryHandler {
status: { httpStatus: 200 }
}
} catch (error) {
CORE_LOGGER.error(`Error in QueryDdoStateHandler: ${error.message}`)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand Down
2 changes: 2 additions & 0 deletions src/components/core/handler/statusHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ValidateParams,
validateCommandParameters
} from '../../httpRoutes/validateCommands.js'
import { CORE_LOGGER } from '../../../utils/logging/common.js'

export class StatusHandler extends Handler {
validate(command: StatusCommand): ValidateParams {
Expand Down Expand Up @@ -34,6 +35,7 @@ export class StatusHandler extends Handler {
status: { httpStatus: 200 }
}
} catch (error) {
CORE_LOGGER.error(`Error in StatusHandler: ${error.message}`)
return {
stream: null,
status: { httpStatus: 500, error: 'Unknown error: ' + error.message }
Expand Down
3 changes: 3 additions & 0 deletions src/components/httpRoutes/logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express'
import { validateAdminSignature } from '../../utils/auth.js'
import { HTTP_LOGGER } from '../../utils/logging/common.js'

export const logRoutes = express.Router()

Expand Down Expand Up @@ -61,6 +62,7 @@ logRoutes.post('/logs', express.json(), validateRequest, async (req, res) => {
res.status(404).send('No logs found')
}
} catch (error) {
HTTP_LOGGER.error(`Error retrieving logs: ${error.message}`)
res.status(500).send(`Internal Server Error: ${error.message}`)
}
})
Expand All @@ -75,6 +77,7 @@ logRoutes.post('/log/:id', express.json(), validateRequest, async (req, res) =>
res.status(404).send('Log not found')
}
} catch (error) {
HTTP_LOGGER.error(`Error retrieving log: ${error.message}`)
res.status(500).send('Internal Server Error' + error.message)
}
})
2 changes: 1 addition & 1 deletion src/test/integration/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ describe('LogDatabase retrieveMultipleLogs with pagination', () => {
})

it('should return empty results for a non-existent page', async () => {
const nonExistentPage = 300 // Assuming this page doesn't exist
const nonExistentPage = 30000 // Assuming this page doesn't exist
const logs = await database.logs.retrieveMultipleLogs(
new Date(Date.now() - 10000), // 10 seconds ago
new Date(), // now
Expand Down

0 comments on commit 77ff139

Please sign in to comment.