我在Node/Express中使用mapquest GeoJson实现时遇到问题。收到错误"正文已使用"



我正在尝试使用mapquest API,我遵循了文档,但我得到了一个错误:HttpError:正文已用于:https://www.mapquestapi.com/geocoding/v1/address?key=

这是我的geoCoder.js设置:

const NodeGeocoder = require('node-geocoder');
const options = {
provider: process.env.GEOCODER_PROVIDER,
//   fetch: customFetchImplementation,
httpAdapter: 'https',
apiKey: process.env.GEOCODER_API_KEY,
formatter: null
};
const geocoder = NodeGeocoder(options);
module.exports = geocoder

这是我的模式:

const mongoose = require('mongoose')
const geocoder = require('../utils/geocoder')

const HomeSchema = new mongoose.Schema({
homeId: {
type: String,
required: [true, 'Please add a home ID'],
unique: true,
trim: true,
maxlength: [10, 'Home ID must be less than 10 characters']
},
address: {
type: String,
required: [true, 'Please add an address']
},
location: {
type: {
type: String, 
enum: ['Point'], 
},
coordinates: {
type: [Number],
index: '2dsphere'
},
formattedAddress: String
},
createdAt: {
type: Date,
default: Date.now
}
})
// Geocode & create location
HomeSchema.pre('save', async function(next) {
const loc = await geocoder.geocode(this.address)
// console.log(loc)
this.location = {
type: 'Point',
coordinates: [loc[0].longitude, loc[0].latitude],
formattedAddress: loc[0].formattedAddress
}
// Do not save address
this.address = undefined
next()
})
module.exports = mongoose.model('Home', HomeSchema)

这是处理请求的控制器:

exports.addHome = async (req, res, next) => {
try {
//    console.log(req.body)
const home = await Home.create(req.body)
return res.status(201).json({
success: true,
data: home
})
} catch (error) {
console.error(error)
if(error.code === 11000) {
return res.status(400).json({ error: 'This home already exists.'})
}
res.status(500).json({error: 'Server error here!'})
}
}

有什么想法可以解释为什么这没有像预期的那样奏效?我在邮递员那里提出的第一个请求是成功的,但之后的一切都失败了。

似乎实际上是我的mapquest帐户没有交易。我创建了一个新帐户来获得一个没有代码更改的新密钥,它成功了。

删除httpAdaptor:https,从选项,它应该工作