This function is called when api hits, Looks like error is in return statement in second do block, it is working good on local host but after deploying on heroku and hitting this api, it says
Could not cast value of type 'Vapor.Request' (0x55e629265b00) to 'Swift.Error' (0x7fd61a06b560).
I faced same error once in localhost and using try fixed that.
func updateInterestInJob(_ req: Request) throws -> Future<SeekerInterestInJob> {
var myInterest = SeekerInterestInJob(userId: 0, annotationId: 0, interest: false, status: 0)
let decoder = JSONDecoder()
guard let data = req.http.body.data else {
throw req as! Error
}
do {
myInterest = try decoder.decode(SeekerInterestInJob.self, from: data)
print("Testing print")
do {
return try SeekerInterestInJob.query(on: req).filter(SeekerInterestInJob.userId, .equal,myInterest.userId).filter(SeekerInterestInJob.providerId, .equal,myInterest.providerId).filter(SeekerInterestInJob.annotationId, .equal,myInterest.annotationId).first().flatMap { (foundInterest) -> EventLoopFuture<SeekerInterestInJob> in
if foundInterest == nil {
print("interest not found")
return myInterest.save(on: req)
}
else {
print("interest found")
foundInterest?.userId = myInterest.userId
foundInterest?.providerId = myInterest.providerId
foundInterest?.annotationId = myInterest.annotationId
if myInterest.status != 0 {
foundInterest?.status = myInterest.status
foundInterest?.interest = foundInterest?.interest
}
else {
foundInterest?.interest = myInterest.interest
}
return (foundInterest?.update(on: req))!
}
}
}
catch {
print("in inner catch block")
return myInterest.update(on: req)
}
}
catch {
print("in outer catch block")
return myInterest.update(on: req)
}
}
question from:
https://stackoverflow.com/questions/65920872/vapor-swift-code-working-on-localhost-but-after-deploying-at-heroku-all-apis-wor 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…