Skip to content

Commit

Permalink
exception translating rest invoker
Browse files Browse the repository at this point in the history
  • Loading branch information
janolaveide committed Jun 4, 2021
1 parent b13fdfd commit 69bf891
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.nav.vedtak.felles.integrasjon.rest.jersey;

import java.io.IOException;
import java.util.List;

import javax.ws.rs.client.Invocation;

import no.nav.vedtak.exception.IntegrasjonException;

public class ExceptionTranslatingInvoker {

private List<Class<? extends Exception>> translatableExceptions;

public ExceptionTranslatingInvoker() {
this(List.of(IOException.class));
}

public ExceptionTranslatingInvoker(List<Class<? extends Exception>> translatableExceptions) {
this.translatableExceptions = translatableExceptions;
}

public <T> T invoke(Invocation i, Class<T> clazz) {
try {
return i.invoke(clazz);
} catch (Exception ex) {
for (var te : translatableExceptions) {
if (te.isAssignableFrom(ex.getClass())) {
throw new IntegrasjonException("F-999999", "Oversatte exception " + ex.getClass().getName(), ex);
}
}
throw ex;
}
}
}

0 comments on commit 69bf891

Please sign in to comment.