Skip to content

Way to intercept an answer from the API #1556

@maxime1992

Description

@maxime1992

Is your feature request related to a problem? Please describe.

If anything goes wrong and we need to get in touch with Stripe team about an HTTP call, we'll be asked to provide the request ID.

I would like to have a way to log every request happening with the request ID.

Looking at the Java implementation, there doesn't seem to be a way to hook into the static request method.

Describe the solution you'd like

Stripe API could provide a method to register interceptors that'd be called when there's an answer.

Describe alternatives you've considered

(Working in Kotlin).

  • Use also on every request and manually log from there. Quite error prone and can even be completely forgotten

  • I could create an inline function for facilitating the logging and avoid repeating too much but it can still be forgotten and would have to be implemented for each type (Customer, etc):

inline fun Customer.logWithRequestId(): Customer {
    LoggerFactory
        .getLogger(this::class.java)
        .info("Created customer ${it.id} (request ID \" ${it.lastResponse.requestId()}\"")
    return this
}

It's also not that good because we don't know here if the Customer object in question was created, updated, removed etc. So we'd have to pass a string or an enum to logWithRequestId and it could be easily forgotten while copy/pasting for example, ending up with the wrong logging... So far from ideal of course.

So none of this is ideal really.

Additional context

No response

Metadata

Metadata

Assignees

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