jcberquist/stripe-cfml

Content-Type doesn't exist

kenricashe opened this issue · 4 comments

Once every couple weeks or so (including today), I get key [Content-Type] doesn't exist from line 122 of stripe.cfc (v3.3.0) when invoking charges.list().

Presuming Stripe API is the root cause.

But should stripe-cfml handle the error or is that solely my responsibility?

Reminds me of Request-Id doesn't exist Issue #38.

Interesting, do you have any idea what the Stripe API is returning in those cases? Obviously the expectation would be that a request to /charges would return JSON with the appropriate "Content-Type" header. I could add a check for the existence of that header before trying to reference it, but it would be nice to know what would happen in that case with your app, presumably you would then be dealing with a different error in your app rather than in stripe-cfml when you don't get the expected response back from stripe-cfml.

Well since stripe-cfml is the black box handling those communications, I don't know what Stripe's API is returning, if anything.

As for my app, I could try/catch, but it would seem cleaner just validating what's returned from stripe-cfml. And based on what stripe-cfml returns, then I'd know what Stripe is returning?

I wonder if there aren't many other devs invoking charges.list()? That might explain why I'm the first to report it.

I've fixed stripe.cfc on my end thusly:

if ( structKeyExists( response.headers, 'Request-Id' ) && structKeyExists( response.headers, 'Content-Type' ) ) {
	response[ 'requestId' ] = response.headers[ 'Request-Id' ];
} else if ( int( response.status ) >= 200 && int( response.status ) < 300 ) {
	throw(
		type = 'StripeResponseException',
		message = 'Request-Id is missing from the response headers',
		extendedInfo = serializeJSON( response )
	);
}

if ( structKeyExists( response.headers, 'Content-Type' ) ) {
	if ( response.headers[ 'Content-Type' ] == 'application/json' ) {
		response.content = deserializeJSON( response.content );
		parsers.response.parse( response.content );
	}
}

Should I submit a pull request?

Sure, a pull request would be great - I would prefer to keep the handling for Request-Id and Content-Type separate, so could you just emulate the logic for Request-Id in the Content-Type handling, without changing the former?