// Path: src/main/java/com/webfluxclient/utils/DataBuffers.java
// public class DataBuffers {
//     
//     public static String readToString(DataBuffer dataBuffer) {
//         try {
//             return FileCopyUtils.copyToString(new InputStreamReader(dataBuffer.asInputStream()));
//         }
//         catch (IOException e) {
//             return e.getMessage();
//         }
//     }
// }


import com.webfluxclient.utils.DataBuffers;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
package com.webfluxclient.codec;


public class HttpServerErrorDecoder implements ErrorDecoder<HttpServerException> {
    @Override
    public boolean canDecode(HttpStatus httpStatus) {
        return httpStatus.is5xxServerError();
    }

    @Override
    public HttpServerException decode(HttpStatus httpStatus, DataBuffer inputMessage) {
// Path: src/main/java/com/webfluxclient/utils/DataBuffers.java
// public class DataBuffers {
//     
//     public static String readToString(DataBuffer dataBuffer) {
//         try {
//             return FileCopyUtils.copyToString(new InputStreamReader(dataBuffer.asInputStream()));
//         }
//         catch (IOException e) {
//             return e.getMessage();
//         }
//     }
// }


// Path: src/main/java/com/webfluxclient/codec/HttpServerErrorDecoder.java
import com.webfluxclient.utils.DataBuffers;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;

package com.webfluxclient.codec;


public class HttpServerErrorDecoder implements ErrorDecoder<HttpServerException> {
    @Override
    public boolean canDecode(HttpStatus httpStatus) {
        return httpStatus.is5xxServerError();
    }

    @Override
    public HttpServerException decode(HttpStatus httpStatus, DataBuffer inputMessage) {
        return new HttpServerException(httpStatus, DataBuffers.readToString(inputMessage));