Group Group Group Group Group Group Group Group Group

Chapter 24: Caching : Crash for second POST


#1

i tried with postman, the 1st time run show error OK, but the 2nd sent POST again will crash… what wrong? @0xtim

p/s : Fixed my mistake, NOW it work OK. … forget replace this code

/// This Pokemon was not cached, we need to query the PokeAPI to verify.
            return self.fetchPokemon(named: name).flatMap { res in
                switch res.http.status.code {
                case 200..<300:
                    /// The API returned 2xx which means this is a real Pokemon name
                    return self.cache.set(key, to: true).transform(to: true)
                case 404:
                    /// The API returned a 404 meaning this Pokemon name was not found.
                    return self.cache.set(key, to: false).transform(to: false)
                default:
                    /// The API returned a 500. Only thing we can do is forward the error.
                    throw Abort(.internalServerError, reason: "Unexpected PokeAPI response: \(res.http.status)")
                }
            }

#2

@tanner0101 Can you please help with this when you get a chance? Thank you - much appreciated! :]


#3

@choioi Fyi this crash was introduced in 3.2.0 of Vapor, so may not have actually been your fault. If you run swift package update you should find it has been fixed