Skip to content

Commit

Permalink
core: include information from www-authenticate in error message
Browse files Browse the repository at this point in the history
Issue #53
  • Loading branch information
gbitzes authored and mpatrascoiu committed Jun 9, 2022
1 parent 03f43a6 commit cf6df90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/backend/StandaloneNeonRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ StandaloneNeonRequest::~StandaloneNeonRequest() {
//------------------------------------------------------------------------------
// Map a neon error to davix error
//------------------------------------------------------------------------------
static void neon_error_mapper(int ne_status, StatusCode::Code & code, std::string & str) {
static void neon_error_mapper(int ne_status, StatusCode::Code & code, std::string & str, const std::string &wwwAuth) {
switch(ne_status){
case NE_OK: {
code = StatusCode::OK;
Expand Down Expand Up @@ -181,6 +181,12 @@ static void neon_error_mapper(int ne_status, StatusCode::Code & code, std::strin
str= "Unknow Error from libneon";
}
}

if(!wwwAuth.empty()) {
str += " (WWW-Authenticate: ";
str += wwwAuth;
str += ")";
}
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -384,7 +390,8 @@ void StandaloneNeonRequest::markCompleted() {
//------------------------------------------------------------------------------
Status StandaloneNeonRequest::createError(int ne_status) {
StatusCode::Code code;
std::string str;
std::string str, wwwAuth;
this->getAnswerHeader("WWW-Authenticate", wwwAuth);

if(ne_status == NE_ERROR && _session) {
const char * neon_error = ne_get_error(_session->get_ne_sess());
Expand All @@ -397,7 +404,7 @@ Status StandaloneNeonRequest::createError(int ne_status) {
}
}
else {
neon_error_mapper(ne_status, code, str);
neon_error_mapper(ne_status, code, str, wwwAuth);
}

return Status(davix_scope_http_request(), code, str);
Expand Down
17 changes: 13 additions & 4 deletions src/neon/neonrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void configureRequestParamsProto(const Uri &uri, RequestParams &params){
}
}

void neon_generic_error_mapper(int ne_status, StatusCode::Code & code, std::string & str){
void neon_generic_error_mapper(int ne_status, StatusCode::Code & code, std::string & str, const std::string &wwwAuth){
switch(ne_status){
case NE_OK:
code = StatusCode::OK;
Expand All @@ -68,7 +68,7 @@ void neon_generic_error_mapper(int ne_status, StatusCode::Code & code, std::stri
break;
case NE_AUTH:
code = StatusCode::AuthenticationError;
str= "Authentification failed on server";
str = "Authentification failed on server";
break;
case NE_PROXYAUTH:
code = StatusCode::AuthenticationError;
Expand All @@ -94,6 +94,12 @@ void neon_generic_error_mapper(int ne_status, StatusCode::Code & code, std::stri
code= StatusCode::UnknowError;
str= "Unknow Error from libneon";
}

if(!wwwAuth.empty()) {
str += "(WWW-Authenticate: ";
str += wwwAuth;
str += ")";
}
}


Expand Down Expand Up @@ -616,6 +622,9 @@ void NeonRequest::freeRequest(){
void NeonRequest::createError(int ne_status, DavixError **err){
StatusCode::Code code;
std::string str;
std::string wwwAuth;
_standalone_req->getAnswerHeader("WWW-Authenticate", wwwAuth);

switch(ne_status){
case NE_ERROR:
{
Expand All @@ -636,12 +645,12 @@ void NeonRequest::createError(int ne_status, DavixError **err){
str+= _current->getString();
break;
}
neon_generic_error_mapper(ne_status, code, str);
neon_generic_error_mapper(ne_status, code, str, wwwAuth);
}
break;

default:
neon_generic_error_mapper(ne_status, code, str);
neon_generic_error_mapper(ne_status, code, str, wwwAuth);
break;
}
DavixError::setupError(err, davix_scope_http_request(), code, str);
Expand Down

0 comments on commit cf6df90

Please sign in to comment.