사례로 보는 예외 처리 JSON 응답 형태
GitHub

예외 참조문서 링크를 함께 응답.

{
    "message": "Not Found",
    "documentation_url": "https://docs.github.com/rest"
}
GitLab

클라이언트에서 사용되지 않을 합의되지 않은 예외 처리 응답은 만들지 않음.

{
    "error": "404 Not Found"
}
BitBucket
{
    "error": "unauthorized_client",
    "error_description": "Invalid OAuth client credentials"
}
Twitter

복수의 에러응답 가능.

{
    "errors": [{
        "code": 215,
        "message": "Bad Authentication data."
    }]
}
Godaddy
{
    "code": "UNABLE_TO_AUTHENTICATE",
    "message": "Unauthorized : Could not authenticate API key/secret"
}
Zoom
{
    "code": 124,
    "message": "Invalid access token."
}
Wikipedia

클라이언트에 사용할 i18n 메시지를 서버에서 관리하고 곧바로 응답.

{
    "httpCode": 404,
    "httpReason": "Not Found",
    "messageTranslations": {
        "en": "The requested relative path (/v1/search/pae) did not match any known handler"
    }
}
Google

복수의 에러응답 가능.

{
    "error": {
        "errors": [{
            "domain": "global",
            "reason": "invalidParameter",
            "message": "Invalid string value: 'asdf'. Allowed values: [mostpopular]",
            "locationType": "parameter",
            "location": "chart"
        }],
        "code": 400,
        "message": "Invalid string value: 'asdf'. Allowed values: [mostpopular]"
    }
}
Facebook

오류 추적을 위한 아이디 사용.

{
    "error": {
        "message": "Message describing the error",
        "type": "OAuthException",
        "code": 190,
        "error_subcode": 460,
        "error_user_title": "A title",
        "error_user_msg": "A message",
        "fbtrace_id": "EJplcsCHuLu"
    }
}
Instagram
{
    "code": 400,
    "error_type": "OAuthException",
    "error_message": "Invalid response type: "
}
Spotify
{
    "error": {
        "status": 502,
        "message": "Bad gateway."
    }
}
Bing

예외 참조문서 링크를 함께 응답.

{
    "SearchResponse": {
        "Version": "2.2",
        "Query": {
            "SearchTerms":"api error codes"
        },
        "Errors":[{
            "Code": 1001,
            "Message": "Required parameter is missing.",
            "Parameter": "SearchRequest.AppId",
            "HelpUrl": "http://msdn.microsoft.com/en-us/flibrary/dd251042.aspx"
        }]
    }
}
IPAPI
{
    "status" : "fail",
    "message": "SSL unavailable for this endpoint, order a key at https://members.ip-api.com/"
}
MicroStrategy
{
    "code": "ERR001",
    "message": "MicroStrategy Intelligence Server is not configured to support LDAP authentication.",
    "iServerCode": -2147205409
}
JuniperNetworks
{
    "message": "test_set does not exist",
    "details": {},
    "description": "The reference set does not exist.",
    "code": 1002,
    "http_response": {
        "message": "We could not find the resource you requested.",
        "code": 404
    }
}
FHIR

경고창에 보여줄 내용을 서버에서 렌더링 후 응답에 포함하여 내려줌.

{
    "resourceType": "OperationOutcome",
    "id": "exception",
    "text": {
        "status": "additional",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n<p>SQL Link Communication Error (dbx = 34234)</p>\n</div>"
    },
    "issue": [{
        "severity": "error",
        "code": "exception",
        "details": {
            "text": "SQL Link Communication Error (dbx = 34234)"
        }
    }]
}

그 외 참고 자료

http://blog.storyg.co/rest-api-response-body-best-pratics

https://developer.orange.com/tech_guide/orange-apis-error-handling/

https://nordicapis.com/best-practices-api-error-handling/

https://www.baeldung.com/rest-api-error-handling-best-practices