Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Invalid request body string serialization #45

@smoliji

Description

@smoliji

I am using cosmas@2.0.0 and provided express hook.

Given following option passed to cosmas initialization

config: {
    serializers: {
        req(req) {
            req.body = 'mystring';
            return loggerSerializers.req(req); // loggerSerializers = require('cosmas/dist/serializers').serializers;
        },
        res(res) {
            return loggerSerializers.res(res);
        },
    },
},

It produces following log:

{"level":50,"severity":"ERROR","time":"2020-06-26T10:50:37.082Z","req":{"body":{"0":"m","1":"y","2":"s","3":"t","4":"r","5":"i","6":"n","7":"g"},"headers":{"user-agent":"PostmanRuntime/7.25.0"},"method":"POST","url":"/trips"},"res":{"time":"1134.818"},"userAgent":"PostmanRuntime/7.25.0","cosmas.pkgVersion":"2.0.0","message":"500 POST /trips - Standard output"}

The problem is in serializing the body as

"body":{"0":"m","1":"y","2":"s","3":"t","4":"r","5":"i","6":"n","7":"g"}

In the serializer, if I set the body as an object like this

req.body = { s: 'mystring' };

body gets logged correctly

"body":{"s":"mystring"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions