Search in sources :

Example 1 with SafeNullPointerException

use of com.palantir.logsafe.exceptions.SafeNullPointerException in project conjure-java-runtime by palantir.

the class EndpointNameHeaderEnrichmentContract method processMetadata.

@Override
protected void processMetadata(Class<?> targetType, Method method, MethodMetadata metadata) {
    String httpMethod = metadata.template().method();
    if (httpMethod == null) {
        throw new SafeNullPointerException("An HTTP method is required", SafeArg.of("class", targetType.getSimpleName()), SafeArg.of("method", method.getName()));
    }
    try {
        HttpMethod.valueOf(httpMethod.toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        throw new SafeIllegalArgumentException("Unsupported HTTP method", SafeArg.of("class", targetType.getSimpleName()), SafeArg.of("method", method.getName()), SafeArg.of("httpMethod", httpMethod));
    }
    metadata.template().header(ENDPOINT_NAME_HEADER, method.getName());
}
Also used : SafeNullPointerException(com.palantir.logsafe.exceptions.SafeNullPointerException) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

Aggregations

SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)1 SafeNullPointerException (com.palantir.logsafe.exceptions.SafeNullPointerException)1