Skip to content

Instantly share code, notes, and snippets.

View cxiaoer's full-sized avatar
🏅
Focusing

cxiaoer

🏅
Focusing
View GitHub Profile
@jonikarppinen
jonikarppinen / CustomErrorController.java
Last active June 16, 2021 02:19
Example of replacing Spring Boot "whitelabel" error page with custom error responses (with JSON response body)
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;