Skip to content

Commit

Permalink
refactor: better fault handling
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Dec 31, 2024
1 parent 4e98c89 commit d03f273
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/src/main/java/sparqles/utils/FaultDiagnostic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.jena.query.QueryException;
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP;
import org.apache.jena.sparql.resultset.ResultSetException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,13 +34,22 @@ public static FaultKind faultKindForJenaQuery(Exception e) {
} else if (e.getCause() instanceof HttpException || qe.getStatusCode() >= 400) {
return faultKindForApacheHttpException(qe.getStatusCode());
}
} else if (e instanceof QueryException) {
}
else if (e instanceof ResultSetException) {
if (e.getMessage().contains("Not a result set syntax:")) {
// (potentially) RDF but not a suitable for this SPARQL query response
return FaultKind.BAD_RESPONSE;
}
log.debug("Unknown fault", e);
return FaultKind.UNKNOWN;
}
else if (e instanceof QueryException) {
if (e.getMessage().contains("Endpoint returned Content-Type:")) {
return FaultKind.BAD_RESPONSE;
}
log.debug("Unknown fault", e);
return FaultKind.UNKNOWN;
} else if (e instanceof HttpException) {
} else if (e instanceof HttpException) {
return faultKindForApacheHttpException(e);
} else if (e instanceof ConnectTimeoutException
|| e instanceof ConnectException
Expand Down

0 comments on commit d03f273

Please sign in to comment.