Skip to content

增加自定义异常方法,用于处理okhttp异步请求时的异常 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

Kingyumu
Copy link

增加自定义异常方法,用于处理okhttp异步请求时的异常

okhttp配置

OkHttpClient okHttpClient = new OkHttpClient
                    .Builder()
                    .addInterceptor(httpLoggingInterceptor)
                    .addInterceptor(new ErrorInterceptor())
                    .connectTimeout(300, TimeUnit.SECONDS)
                    .writeTimeout(300, TimeUnit.SECONDS)
                    .readTimeout(300, TimeUnit.SECONDS)
                    .sslSocketFactory(OkHttpUtil.getIgnoreInitedSslContext().getSocketFactory(), OkHttpUtil.IGNORE_SSL_TRUST_MANAGER_X509)
                    .hostnameVerifier(OkHttpUtil.getIgnoreSslHostnameVerifier())
//                .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10809)))
                    .build();

测试代码:

@Test
public void test_chatCompletions_stream() {
    ChatCompletion chatCompletion = deepSeekConfig.chatCompletionBuilder()
            .message(ChatMessage.withUser("你知道葫芦娃吗"))
            .build();

    // 构造监听器
    SseListener sseListener = new SseListener() {
        @Override
        protected void error(Throwable t, Response response) {
            log.error("回调的异常", t);
        }

        @Override
        protected void send() {
            System.out.print(this.getCurrStr());
        }
    };
    try {
        chatService.chatCompletionStream(chatCompletion, sseListener);
    } catch (Exception e) {
        log.error("主线程异常", e);
    }
}

操作:设置错误的key,运行代码

测试日志:
image

结论:满足期望,能捕获并处理okhttp异步请求时触发的异常和抛出的自定义异常

isxuwl and others added 6 commits October 16, 2024 15:50
* README-EN

* README-EN

* readme添加项目背景介绍

* readme添加项目背景介绍

* minimax-part1

* minimax-part-v1

* minimax-part

* minimax-part

* minimax-part

* minimax-part

* minimax

* minimax-part-dev

---------

Co-authored-by: xuwenlong <xuwenlong@guance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants