1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.net.impl; 6 7 import static org.chromium.net.impl.HttpEngineNativeProvider.EXT_API_LEVEL; 8 import static org.chromium.net.impl.HttpEngineNativeProvider.EXT_VERSION; 9 10 import androidx.annotation.RequiresExtension; 11 12 @RequiresExtension(extension = EXT_API_LEVEL, version = EXT_VERSION) 13 class AndroidNetworkExceptionWrapper extends org.chromium.net.NetworkException { 14 private final android.net.http.NetworkException mBackend; 15 AndroidNetworkExceptionWrapper(android.net.http.NetworkException backend)16 AndroidNetworkExceptionWrapper(android.net.http.NetworkException backend) { 17 this(backend, false); 18 } 19 AndroidNetworkExceptionWrapper( android.net.http.NetworkException backend, boolean expectQuicException)20 AndroidNetworkExceptionWrapper( 21 android.net.http.NetworkException backend, boolean expectQuicException) { 22 super(backend.getMessage(), backend); 23 this.mBackend = backend; 24 25 if (!expectQuicException && backend instanceof android.net.http.QuicException) { 26 throw new IllegalArgumentException( 27 "Translating QuicException as NetworkException results in loss of information. " 28 + "Make sure you handle QuicException first. See the stacktrace " 29 + "for where the translation is being performed, and the cause " 30 + "for the exception being translated.", 31 backend); 32 } 33 } 34 35 @Override getErrorCode()36 public int getErrorCode() { 37 return mBackend.getErrorCode(); 38 } 39 40 @Override getCronetInternalErrorCode()41 public int getCronetInternalErrorCode() { 42 // TODO(danstahr): Hidden API 43 return -1; 44 } 45 46 @Override immediatelyRetryable()47 public boolean immediatelyRetryable() { 48 return mBackend.isImmediatelyRetryable(); 49 } 50 } 51