[英]SvelteKit UnhandledPromiseRejection with strange TLS Connection error
I have here a strange collection of error, for which i canno't find any solutions on the inte.net ( maby i'm just bad with google ).我这里有一个奇怪的错误集合,我无法在 inte.net 上找到任何解决方案(也许我只是对谷歌不好)。
I created a website, with the following files/folder tree:我创建了一个网站,其中包含以下文件/文件夹树:
With this setup i first got this error message:通过此设置,我首先收到此错误消息:
Client.network socket disconnected before secure TLS connection was established. Client.network 套接字在建立安全 TLS 连接之前断开连接。
Which I didn't find any solution for other then reload the page.我没有找到其他解决方案,然后重新加载页面。 After deciding handling the error myself i tried this:在决定自己处理错误后,我尝试了这个:
api.js api.js
import axios from 'axios';
import axiosRetry from 'axios-retry';
const base = process.env['API_ENDPOINT'];
axiosRetry(axios, { retries: 5 });
async function send({ path }) {
let pages = 0;
let resp;
try {
resp = await axios.get(`${base}/${path}`);
} catch (error) {
throw error;
}
if ('X-WP-TotalPages' in resp.headers) {
pages = resp.headers['X-WP-TotalPages'];
}
return {
pages: pages,
body: resp.data
};
}
export async function get(path) {
return send({ method: 'GET', path });
}
And i call it in (for example) landing.js:我在(例如)landing.js 中称它为:
import { writable } from 'svelte/store';
import { browser } from '$app/env';
import * as api from '$lib/api';
let loading = false;
let posts = [];
const list = writable({
loading,
posts
});
export default {
subscribe: list.subscribe,
async fetchNews() {
if (loading) return {};
loading = true;
list.set({ loading, posts });
let lang = 'de';
if (browser) {
lang = localStorage.getItem('lang') || 'de';
}
try {
const res = await api.get(`posts?filter[lang]=${lang}&per_page=4&_embed`);
} catch (error) {
throw error;
}
posts = await res.body;
posts.map((post) => {
if (post._embedded['wp:featuredmedia'])
post.image = post._embedded['wp:featuredmedia'][0].source_url;
else post.image = '/news/news_placeholder.png';
});
loading = false;
list.set({ loading, posts });
}
};
Now the new error is something like this:现在新的错误是这样的:
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with.catch(). [UnhandledPromiseRejection:此错误源于在没有 catch 块的情况下抛出异步 function,或者拒绝未使用 .catch() 处理的 promise。 The promise rejected with the reason "Test".] { code: 'ERR_UNHANDLED_REJECTION' } promise 被拒绝,原因是“测试”。] { code: 'ERR_UNHANDLED_REJECTION' }
Maybe I'm just an idiot right, but i need really some help here!也许我只是个白痴,但我真的需要一些帮助!
Thanks in advance for this.在此先感谢您。
Try wrapping the whole function body in try {...}, instead of the const res = await api.get...
line and observe where exactly the error happens.尝试将整个 function 主体包装在 try {...} 中,而不是const res = await api.get...
行并观察错误发生的确切位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.