简体   繁体   English

SvelteKit UnhandledPromiseRejection 出现奇怪的 TLS 连接错误

[英]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.

相关问题 抛出错误 UnhandledPromiseRejection 后,NodeJS 程序未退出 - NodeJS program is not exiting after throwing an error UnhandledPromiseRejection UnhandledPromiseRejection:错误:Joi 的消息选项无效 - UnhandledPromiseRejection: Error: Invalid message options with Joi 节点js TLS未连接错误连接失败?怎么抓? - Node js TLS uncaught error on connection fail? How to catch? MQTT TLS 连接 - MQTT TLS connection 开玩笑:卡在 [UnhandledPromiseRejection:此错误源于在没有 catch 块的情况下抛出异步 function 内部, - Jest: stuck on [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, 如何修复 repl.it 中未处理的承诺拒绝。 我说的错误“无法读取 q 的属性” - How to fix an unhandledpromiserejection in repl.it. The error I had said "cannot read the property of q" 如何在捕获中抛出错误,而不是 UnhandledPromiseRejection - How can I throw an error from within a catch, without it being an UnhandledPromiseRejection 使用 SvelteKit 创建 Mapboxmap 会导致 500 Internal Error - Creating a Mapboxmap with SvelteKit results in 500 Internal Error Firebase 函数上的“错误:在建立安全 TLS 连接之前客户端网络套接字已断开连接” - "Error: Client network socket disconnected before secure TLS connection was established" on Firebase Function 错误:客户端网络套接字在与 Spotify 建立安全 TLS 连接之前断开连接 - Error: Client network socket disconnected before secure TLS connection was established with Spotify
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM