formatLogLine wrote the fields of a log call with JSON.stringify. A
circular reference threw, so Strapi's error middleware lost the error
it was logging: the axios error of a failed PayPal token request holds
its request object, which refers to itself. An Error was written as {},
and the config.headers of an axios error carried "Authorization: Basic"
with the base64 of the PayPal client id and secret into the line.
The fields are now copied before they are written:
- a field named like a credential (authorization, cookie, password,
secret, token, api key) is written as "[redacted]", at any depth;
- an Error is written as { name, message }, with the first line of the
message as describeError has it, and its stack only with the stack
option;
- an object that contains itself is written once, the reference to it
as "[Circular]";
- an instance of a class is written as its toJSON(), or as its class
name without one: a request object keeps its headers in _header;
- a bigint is written as its digits, an unreadable field as
"[unreadable]".
The three todo tests of the formatter pass and are regular tests now.
Refs libretech/mp#71
Refs libretech/mp#67
describeError keeps an error's name, the first line of its message, cut
to 200 characters, and its HTTP status code. An error of the PayPal SDK
or of axios carries its request, whose Authorization header holds the
PayPal client credentials or an access token, so the error object itself
must not reach the log. The SDK's response validation error quotes the
response values on the lines after the first.
Refs libretech/mp#71