Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error metrics #1140

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
"@mojaloop/central-services-health": "15.0.0",
"@mojaloop/central-services-logger": "11.5.1",
"@mojaloop/central-services-metrics": "12.4.2",
"@mojaloop/central-services-shared": "18.14.1",
"@mojaloop/central-services-shared": "18.15.0",
"@mojaloop/central-services-stream": "11.4.1",
"@mojaloop/database-lib": "11.0.6",
"@mojaloop/database-lib": "11.1.0",
"@mojaloop/event-sdk": "14.1.1",
"@mojaloop/inter-scheme-proxy-cache-lib": "2.3.1",
"@mojaloop/ml-number": "11.2.4",
Expand All @@ -104,8 +104,8 @@
"ajv-keywords": "5.1.0",
"base64url": "3.0.1",
"blipp": "4.0.2",
"commander": "12.1.0",
"cron": "3.3.1",
"commander": "13.0.0",
"cron": "3.3.2",
"decimal.js": "10.4.3",
"docdash": "2.0.2",
"event-stream": "4.0.1",
Expand Down Expand Up @@ -135,7 +135,7 @@
"jsonpath": "1.1.1",
"mock-knex": "0.4.13",
"nodemon": "3.1.9",
"npm-check-updates": "17.1.11",
"npm-check-updates": "17.1.13",
"nyc": "17.1.0",
"pre-commit": "1.2.2",
"proxyquire": "2.1.3",
Expand Down
5 changes: 2 additions & 3 deletions src/api/ledgerAccountTypes/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

const LedgerAccountTypesService = require('../../domain/ledgerAccountTypes')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Logger = require('@mojaloop/central-services-logger')
const { rethrow } = require('@mojaloop/central-services-shared').Util

const getAll = async function () {
return LedgerAccountTypesService.getAll()
Expand All @@ -42,8 +42,7 @@ async function create (request, h) {
return h.response().code(201)
}
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'ledgerAccountTypesCreate' })
}
}

Expand Down
40 changes: 14 additions & 26 deletions src/api/participants/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Logger = require('@mojaloop/central-services-logger')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Enums = require('../../lib/enumCached')
const SettlementService = require('../../domain/settlement')
const { rethrow } = Util

const LocalEnum = {
activated: 'activated',
Expand Down Expand Up @@ -107,8 +108,7 @@ const create = async function (request, h) {
}
return h.response(entityItem(participant, ledgerAccountIds)).code(201)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantCreate' })
}
}

Expand Down Expand Up @@ -152,8 +152,7 @@ const createHubAccount = async function (request, h) {
const ledgerAccountIds = Util.transpose(ledgerAccountTypes)
return h.response(entityItem(participant, ledgerAccountIds)).code(201)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantCreateHubAccount' })
}
}

Expand Down Expand Up @@ -187,8 +186,7 @@ const update = async function (request) {
const ledgerAccountIds = Util.transpose(ledgerAccountTypes)
return entityItem(updatedEntity, ledgerAccountIds)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantUpdate' })
}
}

Expand All @@ -197,8 +195,7 @@ const addEndpoint = async function (request, h) {
await ParticipantService.addEndpoint(request.params.name, request.payload)
return h.response().code(201)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAddEndpoint' })
}
}

Expand Down Expand Up @@ -228,8 +225,7 @@ const getEndpoint = async function (request) {
return endpoints
}
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetEndpoint' })
}
}

Expand All @@ -238,8 +234,7 @@ const addLimitAndInitialPosition = async function (request, h) {
await ParticipantService.addLimitAndInitialPosition(request.params.name, request.payload)
return h.response().code(201)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAddLimitAndInitialPosition' })
}
}

Expand All @@ -261,8 +256,7 @@ const getLimits = async function (request) {
}
return limits
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetLimits' })
}
}

Expand All @@ -285,8 +279,7 @@ const getLimitsForAllParticipants = async function (request) {
}
return limits
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: ' participantGetLimitsForAllParticipants' })
}
}

Expand All @@ -305,26 +298,23 @@ const adjustLimits = async function (request, h) {
}
return h.response(updatedLimit).code(200)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAdjustLimits' })
}
}

const getPositions = async function (request) {
try {
return await ParticipantService.getPositions(request.params.name, request.query)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetPositions' })
}
}

const getAccounts = async function (request) {
try {
return await ParticipantService.getAccounts(request.params.name, request.query)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetAccounts' })
}
}

Expand All @@ -341,8 +331,7 @@ const updateAccount = async function (request, h) {
}
return h.response().code(200)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantUpdateAccount' })
}
}

Expand All @@ -352,8 +341,7 @@ const recordFunds = async function (request, h) {
await ParticipantService.recordFundsInOut(request.payload, request.params, enums)
return h.response().code(202)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantRecordFunds' })
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/api/settlementModels/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Enums = require('../../lib/enumCached')
const Util = require('@mojaloop/central-services-shared').Util
const Enum = require('@mojaloop/central-services-shared').Enum.Settlements
const Logger = require('@mojaloop/central-services-logger')
const { rethrow } = Util

const entityItem = ({ settlementModelId, name, isActive, settlementGranularityId, settlementInterchangeId, settlementDelayId, currencyId, requireLiquidityCheck, ledgerAccountTypeId, autoPositionReset }, ledgerAccountIds, settlementGranularityIds, settlementInterchangeIds, settlementDelayIds) => {
return {
Expand Down Expand Up @@ -90,17 +91,15 @@ const update = async function (request) {
const settlementDelayIds = Util.transpose(Enum.SettlementDelay)
return entityItem(updatedEntity, ledgerAccountIds, settlementGranularityIds, settlementInterchangeIds, settlementDelayIds)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'settlementModelUpdate' })
}
}
const create = async function (request, h) {
try {
await SettlementService.createSettlementModel(request.payload)
return h.response().code(201)
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'settlementModelCreate' })
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/transactions/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
******/
'use strict'

const Transaction = require('../../domain/transactions')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Logger = require('@mojaloop/central-services-logger')
const { rethrow } = require('@mojaloop/central-services-shared').Util

const Transaction = require('../../domain/transactions')

const getById = async function (request) {
try {
Expand All @@ -36,8 +37,7 @@ const getById = async function (request) {
}
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, 'The requested resource could not be found.')
} catch (err) {
Logger.isErrorEnabled && Logger.error(err)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
rethrow.rethrowAndCountFspiopError(err, { operation: 'transactionsGetById' })
}
}

Expand Down
Loading