Replace LicenseExpiredException with ElasticsearchException.WithRestHeadersException

Original commit: elastic/x-pack-elasticsearch@36aaccc0b9
This commit is contained in:
Areek Zillur 2015-07-02 16:34:40 -04:00
parent e5cd37a9af
commit e0e4f07348
2 changed files with 27 additions and 31 deletions

View File

@ -1,31 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin.core;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.rest.RestStatus;
/**
* Exception to be thrown when a feature action requires a valid license
*/
public class LicenseExpiredException extends ElasticsearchException {
private final String feature;
public LicenseExpiredException(String feature) {
super("license expired for feature [" + feature + "]");
this.feature = feature;
}
@Override
public RestStatus status() {
return RestStatus.UNAUTHORIZED;
}
public String feature() {
return feature;
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin.core;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.collect.Tuple;
public class LicenseUtils {
public final static String EXPIRED_FEATURE_HEADER = "es.license.expired.feature";
/**
* Exception to be thrown when a feature action requires a valid license, but license
* has expired
*
* <code>feature</code> accessible through {@link #EXPIRED_FEATURE_HEADER} in the
* exception's rest header
*/
public static ElasticsearchException newExpirationException(String feature) {
// TODO: after https://github.com/elastic/elasticsearch/pull/12006 use ElasicsearchException with addHeader(EXPIRED_FEATURE_HEADER, feature)
return new ElasticsearchException.WithRestHeadersException("license expired for feature [" + feature + "]",
Tuple.tuple(EXPIRED_FEATURE_HEADER, new String[] {feature}));
}
}