Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform StripeError to AbortError #96

Closed
Joebayld opened this issue Mar 11, 2019 · 1 comment
Closed

Conform StripeError to AbortError #96

Joebayld opened this issue Mar 11, 2019 · 1 comment

Comments

@Joebayld
Copy link

Joebayld commented Mar 11, 2019

I have error middleware in place so that my API gets properly formatted errors. When trying to conform the StripeError to AbortError, the responses are still in the format of StripeErrors. Any insight on this?

I tried the following:

extension StripeError: AbortError {
    public var status: HTTPResponseStatus {
        return .badRequest
    }
    
    public var reason: String {
        return "because it failed..."
    }   
}

For some reason, I'm also getting status code 200 for errors..

@Joebayld
Copy link
Author

Joebayld commented Mar 11, 2019

After talking to the vapor folks.. StripeError is conforming to ResponseEncodable and as of Vapor 3.3.0 this will by default return the StripeError and not my custom implementation.

To fix this.. we need to make the StripeError either not conform to ResponseEncodable or to make it properly format the response (this should be user configurable)

One option would be to make StripeAPIError conform to only Decodable and not to Codable. I did that on my end and it fixed it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants