본문으로 바로가기

REST API error 처리

category TwitchEmotesRanking/Backend 2022. 1. 18. 17:11

| API Gateway

Method Response -> statusCode 추가 

-statusCode : { 2xx : 성공 ,  4xx : 클라이언트 에러 , 5xx: 서버에러 }

Integration Response -> Lambda regex 와 연결

 

| Lambda

def lambda_handler(event, context):
    try:
    	return {
            'statusCode': 200,
            'body':json.dumps(data),
        }
        
    except Exception as e:
        return {
            'statusCode': 404,
            'body':json.dumps(e),
        }