Skip to content
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
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ app.use((req, res, next) => {
app.use((err, req, res, next) => {
res.locals.message = err.message;
res.locals.error = process.env.NODE_ENV !== "production" ? err : {};

// 상태 코드가 있으면 사용, 없으면 500으로 설정

const statusCode = err.status || status.INTERNAL_SERVER_ERROR;

console.error("Error Stack:", err.stack);
console.error("Error Data:", err.data);
res
.status(statusCode)
.send(response(err.data || { message: "Internal Server Error" }));
});

// 응답은 response()로 포맷팅하되, statusCode는 숫자로 분리
const responseBody = response(err.data || {
code: 'COMMON000',
isSuccess: false,
message: 'Internal Server Error',
result: null,
});

res.status(statusCode).json(responseBody); // ✅ send → json도 좋음
});

//sample
app.listen(app.get("port"), () => {
Expand Down
26 changes: 15 additions & 11 deletions src/controllers/music.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ export const insertMusicController=async(req,res,next)=>{
// music info 불러오는 Controller
export const musicInfoController = async (req, res, next) => {
try {
const token = req.headers.authorization.split(' ')[1];;
console.log(token);
const decoded = jwt.decode(token);
console.log(decoded);
const userId = decoded.req.id;
const songId = req.params.id;
const musicInfo = await musicInfoService(userId, songId);
res.send(response(status.SUCCESS, musicInfo));
const token = req.headers.authorization?.split(' ')[1];
const decoded = jwt.decode(token);
const userId = decoded?.id;
const songId = req.params.id;

if (!userId) throw new BaseError(status.UNAUTHORIZED);

const musicInfo = await musicInfoService(userId, songId);
res.status(status.SUCCESS.status).json(response(status.SUCCESS, musicInfo));

} catch (error) {
console.error(error);
res.send(response(status.BAD_REQUEST, BaseError(status.BAD_REQUEST)));
console.error(error);

const errStatus = error instanceof BaseError ? error.status : status.BAD_REQUEST.status;
res.status(errStatus).json(response(status.BAD_REQUEST));
}
};
};


// music change-info(update) Controller
Expand Down
Loading