Skip to content

Commit

Permalink
Merge branch 'release/0.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Mar 30, 2023
2 parents c162f64 + 2b30071 commit c86dc0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treblle/sails",
"version": "0.0.3",
"version": "0.0.4",
"description": "Sails hook for Treblle",
"main": "index.js",
"sails": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"sails": ">=1"
},
"dependencies": {
"@treblle/utils": "^0.1.9"
"@treblle/utils": "^0.1.10"
},
"devDependencies": {
"husky": "^8.0.3",
Expand Down
33 changes: 6 additions & 27 deletions private/treblle-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
generateTrebllePayload,
getRequestDuration,
sendPayloadToTreblle,
getResponsePayload,
} = require('@treblle/utils')

const { version: sdkVersion } = require('../package.json')
Expand Down Expand Up @@ -38,33 +39,11 @@ module.exports = function treblleMiddleware(req, res, next) {

const protocol = `${req.protocol}/${req.httpVersion}`

let originalResponseBody = res._treblleResponsebody
let maskedResponseBody
try {
if (Buffer.isBuffer(res.payload)) {
originalResponseBody = originalResponseBody.toString('utf8')
}
if (typeof originalResponseBody === 'string') {
let parsedResponseBody = JSON.parse(originalResponseBody)
maskedResponseBody = maskSensitiveValues(
parsedResponseBody,
fieldsToMask
)
} else if (typeof originalResponseBody === 'object') {
maskedResponseBody = maskSensitiveValues(
originalResponseBody,
fieldsToMask
)
}
} catch (error) {
// if we can't parse the body we'll leave it empty and set an error
errors.push({
source: 'onShutdown',
type: 'INVALID_JSON',
message: 'Invalid JSON format',
file: null,
line: null,
})
const { payload: maskedResponseBody, error: invalidResponseBodyError } =
getResponsePayload(res._treblleResponsebody, fieldsToMask)

if (invalidResponseBodyError) {
errors.push(invalidResponseBodyError)
}

// Treblle Payload
Expand Down

0 comments on commit c86dc0f

Please sign in to comment.