Skip to content

FeignConfig errorDecoder 추가 및 로깅 코드 추가 #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.Builder;
import lombok.Data;
import lombok.ToString;

import java.time.OffsetDateTime;
import java.util.UUID;

@Builder
@Data
@ToString
public class PaymentObject {
private String mId;
private String lastTransactionKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import com.clip.order.entity.OneThingOrder;
import com.clip.order.entity.RandomOrder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class PaymentServiceFacade {
Expand All @@ -27,6 +29,7 @@ public void confirm(long userId, PaymentDto paymentDto) {
.amount(randomOrder.getDiscountedPrice())
.build()
);
log.info("paymentObject info: {}", paymentObject.toString());
userPaymentService.updateRandomOrderStatus(userId, paymentObject);
}
case ONETHING -> {
Expand All @@ -37,6 +40,7 @@ public void confirm(long userId, PaymentDto paymentDto) {
.amount(oneThingOrder.getDiscountedPrice())
.build()
);
log.info("paymentObject info: {}", paymentObject.toString());
userPaymentService.updateOneThingOrderStatus(userId, paymentObject);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.clip.global.config.feign;

import feign.RequestInterceptor;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Base64;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

@Slf4j
@Configuration
public class FeignConfig {

Expand All @@ -19,6 +23,15 @@ public RequestInterceptor authorizationHeader() {
return requestTemplate -> requestTemplate.header("Authorization", getEncodedSecretKey());
}

@Bean
public ErrorDecoder errorDecoder() {
return (methodKey, response) -> {
String errorMessage = Objects.isNull(response.body()) ? "No response body" : response.body().toString();
log.error("Feign client error: Method Key - {}, Status Code - {}, Response Body - {}", methodKey, response.status(), errorMessage);
return new ErrorDecoder.Default().decode(methodKey, response);
};
}

private String getEncodedSecretKey() {
String key = tossSecretKey + ":";
return "Basic " + new String(Base64.encode(key.getBytes(StandardCharsets.UTF_8)));
Expand Down