comparison Core/RestApi/RestApiOutput.cpp @ 1567:9c5d93510414

If error while calling the REST API, the answer body contains an error description
author jodogne
date Sun, 23 Aug 2015 09:49:16 +0200
parents 3606278d305e
children bd1889029cbb
comparison
equal deleted inserted replaced
1566:3be6eb3757c8 1567:9c5d93510414
133 CheckStatus(); 133 CheckStatus();
134 output_.Redirect(path); 134 output_.Redirect(path);
135 alreadySent_ = true; 135 alreadySent_ = true;
136 } 136 }
137 137
138 void RestApiOutput::SignalError(HttpStatus status) 138 void RestApiOutput::SignalErrorInternal(HttpStatus status,
139 const char* message,
140 size_t messageSize)
139 { 141 {
140 if (status != HttpStatus_400_BadRequest && 142 if (status != HttpStatus_400_BadRequest &&
141 status != HttpStatus_403_Forbidden && 143 status != HttpStatus_403_Forbidden &&
142 status != HttpStatus_500_InternalServerError && 144 status != HttpStatus_500_InternalServerError &&
143 status != HttpStatus_415_UnsupportedMediaType) 145 status != HttpStatus_415_UnsupportedMediaType)
144 { 146 {
145 throw OrthancException("This HTTP status is not allowed in a REST API"); 147 throw OrthancException("This HTTP status is not allowed in a REST API");
146 } 148 }
147 149
148 CheckStatus(); 150 CheckStatus();
149 output_.SendStatus(status); 151 output_.SendStatus(status, message, messageSize);
150 alreadySent_ = true; 152 alreadySent_ = true;
153 }
154
155 void RestApiOutput::SignalError(HttpStatus status)
156 {
157 SignalErrorInternal(status, NULL, 0);
158 }
159
160 void RestApiOutput::SignalError(HttpStatus status,
161 const std::string& message)
162 {
163 SignalErrorInternal(status, message.c_str(), message.size());
151 } 164 }
152 165
153 void RestApiOutput::SetCookie(const std::string& name, 166 void RestApiOutput::SetCookie(const std::string& name,
154 const std::string& value, 167 const std::string& value,
155 unsigned int maxAge) 168 unsigned int maxAge)