This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit d294525b authored by Philipp Gritsch's avatar Philipp Gritsch
Browse files

Merge branch '546-edu-sharing-integration-nicht-erreichbarkeit-besser-handlen' into 'development'

Resolve "Edu-Sharing Integration: Nicht-Erreichbarkeit besser handlen"

See merge request !280
parents dd3f4d98 2b1235b3
Branches
2 merge requests!284Preparing August Release,!280Resolve "Edu-Sharing Integration: Nicht-Erreichbarkeit besser handlen"
......@@ -3,6 +3,7 @@ package at.ac.uibk.gitsearch.config;
import at.ac.uibk.gitsearch.edu_sharing.model.Authority;
import at.ac.uibk.gitsearch.properties.ApplicationProperties;
import at.ac.uibk.gitsearch.service.edu_sharing.EduSharingConfiguration;
import at.ac.uibk.gitsearch.service.edu_sharing.EduSharingUnavailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -64,6 +65,21 @@ public class EduSharingApiConfiguration {
.builder()
.baseUrl(eduSharingUrl)
.filter(new EduSharingLogger())
.filter((request, next) ->
next
.exchange(request)
.flatMap(response -> {
if (response.statusCode().value() == 503) {
return response
.bodyToMono(String.class)
.flatMap(errorBody -> {
return Mono.error(new EduSharingUnavailableException("Error response: " + errorBody));
});
} else {
return Mono.just(response);
}
})
)
.defaultHeaders(header -> header.setBasicAuth(user, password))
.build();
}
......
package at.ac.uibk.gitsearch.service.edu_sharing;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class EduSharingExceptionHandlingAspect {
@AfterThrowing(pointcut = "execution(* at.ac.uibk.gitsearch.service.edu_sharing.EduSharingService.*(..))", throwing = "e")
public void handleEduServiceExceptions(Throwable e) throws Throwable {
Throwable cause = unwrapException(e);
if (cause instanceof EduSharingUnavailableException) {
throw (EduSharingUnavailableException) cause;
} else {
throw e;
}
}
private Throwable unwrapException(Throwable e) {
if (e.getCause() != null) {
return unwrapException(e.getCause());
}
return e;
}
}
package at.ac.uibk.gitsearch.service.edu_sharing;
public class EduSharingUnavailableException extends RuntimeException {
private static final long serialVersionUID = 1L;
public EduSharingUnavailableException(String message) {
super(message);
}
}
......@@ -14,6 +14,7 @@ public final class ErrorConstants {
public static final URI LOGIN_ALREADY_USED_TYPE = URI.create(PROBLEM_BASE_URL + "/login-already-used");
public static final URI METADATA_NON_COMPLIANT_TYPE = URI.create(PROBLEM_BASE_URL + "/metadata-non-compliant");
public static final URI EDU_SHARING_UNAVAILABLE_TYPE = URI.create(PROBLEM_BASE_URL + "/edu-sharing-unavailable");
private ErrorConstants() {}
}
package at.ac.uibk.gitsearch.web.rest.errors;
import at.ac.uibk.gitsearch.service.edu_sharing.EduSharingUnavailableException;
import at.ac.uibk.gitsearch.service.edu_sharing.MetadataComplianceException;
import java.net.URI;
import java.util.Arrays;
......@@ -38,6 +39,7 @@ import tech.jhipster.web.util.HeaderUtil;
* The error response follows RFC7807 - Problem Details for HTTP APIs (https://tools.ietf.org/html/rfc7807).
*/
@ControllerAdvice
@SuppressWarnings("PMD.TooManyMethods")
public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait {
private static final String FIELD_ERRORS_KEY = "fieldErrors";
......@@ -172,6 +174,17 @@ public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait
return create(ex, problem, request);
}
@ExceptionHandler(EduSharingUnavailableException.class)
public ResponseEntity<Problem> handleEduSharingUnavailableException(EduSharingUnavailableException ex, NativeWebRequest request) {
Problem problem = Problem
.builder()
.withStatus(Status.SERVICE_UNAVAILABLE)
.withType(ErrorConstants.EDU_SHARING_UNAVAILABLE_TYPE)
.with(MESSAGE_KEY, "Edusharing is unavailable")
.build();
return create(ex, problem, request);
}
@Override
public ProblemBuilder prepare(final @Nonnull Throwable throwable, final @Nonnull StatusType status, final @Nonnull URI type) {
Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
......
......@@ -301,6 +301,8 @@ export class ExerciseBodyComponent implements OnInit, OnDestroy, AfterViewInit {
console.log('User is not allowed to upload to edu-sharing')
} else if (status === 404) {
console.log('Exercise not found')
} else if (status === 503 && error?.error.type == 'https://www.jhipster.tech/problem/edu-sharing-unavailable') {
this.eduSharingExportViolations.push('EDU_SHARING_UNAVAILABLE')
} else if (status >= 500) {
this.eduSharingExportViolations.push('UNKNOWN_ERROR')
}
......
......@@ -171,6 +171,7 @@
},
"exportViolations": {
"UNKNOWN_ERROR": "Ein unbekannter Fehler ist aufgetreten",
"EDU_SHARING_UNAVAILABLE": "Edu-Sharing ist nicht verfügbar",
"COLLECTIONS_NOT_SUPPORTED": "Sammlungen werden nicht unterstützt",
"LICENSE_INVALID": "Lizenz ist ungültig",
"LICENSE_NOT_SUPPORTED": "Es werden nur CC-BY-SA 4.0 oder CC0 Lizenzen unterstützt",
......
......@@ -171,6 +171,7 @@
},
"exportViolations": {
"UNKNOWN_ERROR": "An unknown error occurred",
"EDU_SHARING_UNAVAILABLE": "Edu-Sharing is not available",
"COLLECTIONS_NOT_SUPPORTED": "Collections are not supported",
"LICENSE_INVALID": "License is invalid",
"LICENSE_NOT_SUPPORTED": "Only CC-BY-SA 4.0 or CC0 licenses are supported",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment