comparison Core/WebServiceParameters.cpp @ 2954:d924f9bb61cc

taking advantage of details in OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 14:35:34 +0100
parents 807169f85ba9
children 4e43e67f8ecf
comparison
equal deleted inserted replaced
2953:210d5afd8f2b 2954:d924f9bb61cc
90 void WebServiceParameters::SetUrl(const std::string& url) 90 void WebServiceParameters::SetUrl(const std::string& url)
91 { 91 {
92 if (!Toolbox::StartsWith(url, "http://") && 92 if (!Toolbox::StartsWith(url, "http://") &&
93 !Toolbox::StartsWith(url, "https://")) 93 !Toolbox::StartsWith(url, "https://"))
94 { 94 {
95 LOG(ERROR) << "Bad URL: " << url; 95 throw OrthancException(ErrorCode_BadFileFormat, "Bad URL: " + url);
96 throw OrthancException(ErrorCode_BadFileFormat);
97 } 96 }
98 97
99 // Add trailing slash if needed 98 // Add trailing slash if needed
100 if (url[url.size() - 1] == '/') 99 if (url[url.size() - 1] == '/')
101 { 100 {
140 throw OrthancException(ErrorCode_ParameterOutOfRange); 139 throw OrthancException(ErrorCode_ParameterOutOfRange);
141 } 140 }
142 141
143 if (certificateKeyPassword.empty()) 142 if (certificateKeyPassword.empty())
144 { 143 {
145 LOG(ERROR) << "The password for the HTTPS certificate is not provided: " << certificateFile; 144 throw OrthancException(
146 throw OrthancException(ErrorCode_BadFileFormat); 145 ErrorCode_BadFileFormat,
146 "The password for the HTTPS certificate is not provided: " + certificateFile);
147 } 147 }
148 148
149 certificateFile_ = certificateFile; 149 certificateFile_ = certificateFile;
150 certificateKeyFile_ = certificateKeyFile; 150 certificateKeyFile_ = certificateKeyFile;
151 certificateKeyPassword_ = certificateKeyPassword; 151 certificateKeyPassword_ = certificateKeyPassword;
171 { 171 {
172 ClearCredentials(); 172 ClearCredentials();
173 } 173 }
174 else if (peer.size() == 2) 174 else if (peer.size() == 2)
175 { 175 {
176 LOG(ERROR) << "The HTTP password is not provided"; 176 throw OrthancException(ErrorCode_BadFileFormat,
177 throw OrthancException(ErrorCode_BadFileFormat); 177 "The HTTP password is not provided");
178 } 178 }
179 else if (peer.size() == 3) 179 else if (peer.size() == 3)
180 { 180 {
181 SetCredentials(peer.get(1u, "").asString(), 181 SetCredentials(peer.get(1u, "").asString(),
182 peer.get(2u, "").asString()); 182 peer.get(2u, "").asString());
362 void WebServiceParameters::AddUserProperty(const std::string& key, 362 void WebServiceParameters::AddUserProperty(const std::string& key,
363 const std::string& value) 363 const std::string& value)
364 { 364 {
365 if (IsReservedKey(key)) 365 if (IsReservedKey(key))
366 { 366 {
367 LOG(ERROR) << "Cannot use this reserved key to name an user property: " << key; 367 throw OrthancException(
368 throw OrthancException(ErrorCode_ParameterOutOfRange); 368 ErrorCode_ParameterOutOfRange,
369 "Cannot use this reserved key to name an user property: " + key);
369 } 370 }
370 else 371 else
371 { 372 {
372 userProperties_[key] = value; 373 userProperties_[key] = value;
373 } 374 }
486 { 487 {
487 if (!certificateFile_.empty()) 488 if (!certificateFile_.empty())
488 { 489 {
489 if (!SystemToolbox::IsRegularFile(certificateFile_)) 490 if (!SystemToolbox::IsRegularFile(certificateFile_))
490 { 491 {
491 LOG(ERROR) << "Cannot open certificate file: " << certificateFile_; 492 throw OrthancException(ErrorCode_InexistentFile,
492 throw OrthancException(ErrorCode_InexistentFile); 493 "Cannot open certificate file: " + certificateFile_);
493 } 494 }
494 495
495 if (!certificateKeyFile_.empty() && 496 if (!certificateKeyFile_.empty() &&
496 !SystemToolbox::IsRegularFile(certificateKeyFile_)) 497 !SystemToolbox::IsRegularFile(certificateKeyFile_))
497 { 498 {
498 LOG(ERROR) << "Cannot open key file: " << certificateKeyFile_; 499 throw OrthancException(ErrorCode_InexistentFile,
499 throw OrthancException(ErrorCode_InexistentFile); 500 "Cannot open key file: " + certificateKeyFile_);
500 } 501 }
501 } 502 }
502 } 503 }
503 #endif 504 #endif
504 } 505 }