Javascript Agent Error Passing
Closed this issue · 4 comments
In the documentation here, it states that getData throws errors directly from our Pro Agent without changing them. However, when calling getData, it occasionally errors with the full error object being:
{"name":"FPJSAgentError"}
I have not yet experienced receiving an error response other than this one and I would estimate that over 95% of my getData requests result in a successful response object. As there isn't much that I can do with this error response to figure out what went wrong, I am posting here in hopes that you have any pointers, answers, or suggestions.
What I would expect to happen is to receive one of the errors from here which this repo's documentation points to here.
Unfortunately, I have not been able to reproduce it myself.
Thanks in advance!
"@fingerprintjs/fingerprintjs-pro-react": "^2.3.3",
"react": "^16.13.1",
Hi, generally it should act like raw JS Agent.
https://github.com/fingerprintjs/fingerprintjs-pro-react/blob/main/src/use-visitor-data.ts#L59
https://github.com/fingerprintjs/fingerprintjs-pro-react/blob/main/src/utils/to-error.ts#L1
Can you provide more context?
- How do you serialize error object? The original error should be in the
error.message
field, I'm worrying in which step we lost it. - How do you catch the error? Is it
async-await
withtry-catch
block aroundgetData
function?
You can simply check the error handling mechanics by turning offline mode in developer tools and calling identification.
This is my usage:
getData().then(
(data) => {
// Send data to server
},
(err) => {
// Send error object to server for logging serializing with JSON.stringify(err)
// Once serialized, the result is {"name":"FPJSAgentError"}
}
);
Is error.message a string? If not, its possible that the serialization is where its getting lost.
Error
object has problems with JSON.stringify
, you can check this question in StackOverflow
This approach from answer works JSON.stringify(err, Object.getOwnPropertyNames(err))
, you can try it.
Or if you don't need a stacktrace
, you can just save name
and message
by calling JSON.stringify(err, Object.getOwnPropertyNames(err), ['name', 'message'])
Or you can just use error.toString()
Thanks so much, Ilya. I really appreciate your help despite the issue not being with fingerprint at all. I'm deploying this change shortly and I definitely expect this to be the resolution to my issue.