All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tencent.trpc.spring.exception.annotation.TRpcHandleException Maven / Gradle / Ivy

/*
 * Tencent is pleased to support the open source community by making tRPC available.
 *
 * Copyright (C) 2023 THL A29 Limited, a Tencent company.
 * All rights reserved.
 *
 * If you have downloaded a copy of the tRPC source code from Tencent,
 * please note that tRPC source code is licensed under the Apache 2.0 License,
 * A copy of the Apache 2.0 License can be found in the LICENSE file.
 */

package com.tencent.trpc.spring.exception.annotation;

import com.tencent.trpc.core.rpc.anno.TRpcMethod;
import com.tencent.trpc.core.rpc.anno.TRpcService;
import com.tencent.trpc.spring.exception.api.ExceptionHandler;
import com.tencent.trpc.spring.exception.api.ExceptionHandlerResolver;
import com.tencent.trpc.spring.exception.api.ExceptionResultTransformer;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Indicates that exception thrown by annotated method(or methods of annotated class)
 * should be handled by {@link ExceptionHandler}s(or {@link TRpcExceptionHandler} annotated methods).
 * 

Should be used on {@link TRpcService} classes or {@link TRpcMethod} methods.

* * Example: *
 * @Service
 * @TRpcHandleException
 * public class TRpcServiceApiImpl implements TRpcServiceApi {
 *
 *     @Override
 *     public Response test(RpcContext context, Request request) {
 *          // do something
 *     }
 *
 *     @Override
 *     @TRpcHandleException(exclude = MyException.class)
 *     public Response doNotCatchMyException(RpcContext context, Request request) {
 *         // do something
 *     }
 * }
* * @see TRpcService * @see TRpcMethod * @see ExceptionHandlerResolver * @see ExceptionHandler * @see ExceptionResultTransformer */ @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface TRpcHandleException { /** * Exception types to be excluded. */ Class[] exclude() default {}; /** * Set the explicit {@link ExceptionHandler} bean to be used. */ String handler() default ""; /** * Set the explicit {@link ExceptionResultTransformer} bean to be used. */ String transform() default ""; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy