@@ -250,12 +250,12 @@ class DownloadTaskCURL : public IDownloadTask
250
250
return status;
251
251
}
252
252
253
- void setErrorProc (int code, int codeInternal, const char * desc)
253
+ void setErrorDesc (int code, int codeInternal, std::string&& desc)
254
254
{
255
255
std::lock_guard<std::recursive_mutex> lock (_mutex);
256
256
_errCode = code;
257
257
_errCodeInternal = codeInternal;
258
- _errDescription = desc;
258
+ _errDescription = std::move ( desc) ;
259
259
}
260
260
261
261
size_t writeDataProc (unsigned char * buffer, size_t size, size_t count)
@@ -617,8 +617,14 @@ class DownloaderCURL::Impl : public std::enable_shared_from_this<DownloaderCURL:
617
617
auto coTask = static_cast <DownloadTaskCURL*>(task->_coTask .get ());
618
618
if (CURLE_OK != errCode)
619
619
{
620
- coTask->setErrorProc (DownloadTask::ERROR_IMPL_INTERNAL, errCode,
621
- curl_easy_strerror (errCode));
620
+ std::string errorMsg = curl_easy_strerror (errCode);
621
+ if (errCode == CURLE_HTTP_RETURNED_ERROR) {
622
+ long responeCode = 0 ;
623
+ curl_easy_getinfo (curlHandle, CURLINFO_RESPONSE_CODE, &responeCode);
624
+ fmt::format_to (std::back_inserter (errorMsg), FMT_COMPILE (" : {}" ), responeCode);
625
+ }
626
+
627
+ coTask->setErrorDesc (DownloadTask::ERROR_IMPL_INTERNAL, errCode, std::move (errorMsg));
622
628
break ;
623
629
}
624
630
@@ -689,7 +695,7 @@ class DownloaderCURL::Impl : public std::enable_shared_from_this<DownloaderCURL:
689
695
690
696
if (nullptr == curlHandle)
691
697
{
692
- coTask->setErrorProc (DownloadTask::ERROR_IMPL_INTERNAL, 0 , " Alloc curl handle failed." );
698
+ coTask->setErrorDesc (DownloadTask::ERROR_IMPL_INTERNAL, 0 , " Alloc curl handle failed." );
693
699
_owner->_onDownloadFinished (*task);
694
700
continue ;
695
701
}
@@ -701,7 +707,7 @@ class DownloaderCURL::Impl : public std::enable_shared_from_this<DownloaderCURL:
701
707
mcode = curl_multi_add_handle (curlmHandle, curlHandle);
702
708
if (CURLM_OK != mcode)
703
709
{
704
- coTask->setErrorProc (DownloadTask::ERROR_IMPL_INTERNAL, mcode, curl_multi_strerror (mcode));
710
+ coTask->setErrorDesc (DownloadTask::ERROR_IMPL_INTERNAL, mcode, curl_multi_strerror (mcode));
705
711
_owner->_onDownloadFinished (*task);
706
712
continue ;
707
713
}
@@ -903,7 +909,7 @@ void DownloaderCURL::_onDownloadFinished(DownloadTask& task, int checkState)
903
909
break ;
904
910
}
905
911
906
- if (coTask._fileName .empty () || DownloadTask::ERROR_NO_ERROR != coTask. _errCode )
912
+ if (coTask._fileName .empty () || coTask. _errCode != DownloadTask::ERROR_NO_ERROR )
907
913
{
908
914
if (coTask._errCodeInternal == CURLE_RANGE_ERROR)
909
915
{
0 commit comments