/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.gateway.handler;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.function.BodyInserters.fromValue;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;

import com.crunii.micro.common.dto.Result;

import reactor.core.publisher.Mono;

/**
 * @author 田平 create 2019年12月3日下午3:45:07
 *
 */
@Component
public class FallbackHandler {

	public Mono<ServerResponse> fallback(ServerRequest request) {
		Result<String> result = new Result<>();
		result.setCode(Result.DEFAULT_ERROR_CODE);
		result.setMsg("fallback return!");
		result.setSuccess(false);
		return ServerResponse.status(HttpStatus.SERVICE_UNAVAILABLE)
				.contentType(APPLICATION_JSON)
				.body(fromValue(result));
	}

}
