본문 바로가기

Playlist/Content

ContentException, ErrorCode

*/domain/content/exception

 

ContentException.java

import com.codeit.playlist.global.constant.ErrorCode;
import com.codeit.playlist.global.error.BusinessException;

public class ContentException extends BusinessException {
    public ContentException(ErrorCode errorCode) {
        super(errorCode);
    }
}

 

 

contentErrorCode.java

import com.codeit.playlist.global.constant.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ContentErrorCode implements ErrorCode {

    CONTENT_BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), "컨텐츠에 대한 잘못된 요청입니다."), // 400
    CONTENT_UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "컨텐츠에 대해 인증되지 않았습니다."), // 401
    CONTENT_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "컨텐츠가 존재하지 않습니다."),
    CONTENT_FORBIDDEN(HttpStatus.FORBIDDEN.value(), "컨텐츠에 대한 잘못된 접근입니다."), // 403
    CONTENT_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "컨텐츠 서버가 폭발했습니다."); // 500

    private final int status;
    private final String message;

    @Override
    public String getErrorCodeName() {
        return name();
    }
}

 

 

ContentBadRequestException.java

import java.util.UUID;

public class ContentBadRequestException extends ContentException {
    public ContentBadRequestException() {
        super(ContentErrorCode.CONTENT_BAD_REQUEST);
    }

    public ContentBadRequestException(String message) {
        super(ContentErrorCode.CONTENT_BAD_REQUEST);
        System.out.println(message);
    }

    public static ContentBadRequestException withId(UUID contentId) {
        ContentBadRequestException exception = new ContentBadRequestException();
        exception.addDetail("contentId", contentId);
        return exception;
    }
}

 

 

ContentForbiddenException.java

import java.util.UUID;

public class ContentForbiddenException extends ContentException {
    public ContentForbiddenException() {
        super(ContentErrorCode.CONTENT_FORBIDDEN);
    }

    public static ContentForbiddenException withId(UUID contentId) {
        ContentForbiddenException exception = new ContentForbiddenException();
        exception.addDetail("contentId", contentId);
        return exception;
    }
}

 

 

ContentInternalErrorException.java

package com.codeit.playlist.domain.content.exception;

import java.util.UUID;

public class ContentInternalErrorException extends ContentException {
    public ContentInternalErrorException() {
        super(ContentErrorCode.CONTENT_INTERNAL_SERVER_ERROR);
    }

    public static ContentInternalErrorException getId(UUID contentId) {
        ContentInternalErrorException exception = new ContentInternalErrorException();
        exception.addDetail("contentId", contentId);
        return exception;
    }
}

 

 

ContentNotFoundException.java

import java.util.UUID;

public class ContentNotFoundException extends ContentException {
    public ContentNotFoundException() {
        super(ContentErrorCode.CONTENT_NOT_FOUND);
    }

    public static ContentNotFoundException withId(UUID contentId) {
        ContentNotFoundException exception = new ContentNotFoundException();
        exception.addDetail("contentId", contentId);
        return exception;
    }
}

 

 

ContentUnauthorizedException.java

import java.util.UUID;

public class ContentUnauthorizedException extends ContentException {
    public ContentUnauthorizedException() {
        super(ContentErrorCode.CONTENT_UNAUTHORIZED);
    }

    public static ContentUnauthorizedException withId(UUID contentId) {
        ContentUnauthorizedException exception = new ContentUnauthorizedException();
        exception.addDetail("contentId", contentId);
        return exception;
    }
}

 

'Playlist > Content' 카테고리의 다른 글

ContentRepository, Custom, Impl  (0) 2025.12.17
ContentMapper  (0) 2025.12.17
Content, DTO  (0) 2025.12.17
ContentController  (0) 2025.12.17
ContentService  (0) 2025.12.17