我目前的代码可以同时获取大约五个 API 调用。
有时一切都会成功,但大多数时候它会返回获取错误。有没有办法可以运行 API 调用而不会出现错误?
app.post("/movie/:movieName/",function(req,res) {
const Title = req.params.movieName
Promise.all([
fetch("https://api.themoviedb.org/3/movie/" + Title + "/videos?=en-us").then(Videos => Videos.json()),
fetch("https://api.themoviedb.org/3/movie/" + Title + "?&language=en-US").then(Movies => Movies.json()),
fetch("https://api.themoviedb.org/3/movie/" + Title + "/credits?&language=en-US").then(Cast => Cast.json()),
fetch("https://api.themoviedb.org/3/movie/now_playing?&language=en-US&page=2").then(Playing => Playing.json()),
fetch("https://api.themoviedb.org/3/movie/" + Title + "/similar?&language=en-US").then(Similar => Similar.json()),
])
.then(function(response) {
const Details = response[1]
const Video = response[0].results[0]
const Cast = response[2].cast
const Similar = response[3].results
const Playing = response[4].results
res.render(
"movie",
{
Details: Details,
Video: Video,
Cast: Cast,
Similar: Similar,
Playing: Playing
}
)
});
});
智慧大石
相关分类