[ADP-405] 啟發性 HTTP 問題重新設計
錯誤重新設計
讓我們根據 RFC9457 (HTTP Problem) 重新設計 RTSP 客戶端代碼庫中這些錯誤:
javascript
case 'Error: Access denied':
case 'Error: Streaming destroying':
case 'Error: The video codec has been changed.':
case 'Error: codec: H264 has been changed':
case 'Error: codec: HEVC has been changed':
case 'Error: Continuous play failed':
case 'Error: Unsupported MIME type':
case 'Error: codec: H265 is not supported':
case 'Error: codec: HEVC is not supported':
case 'Error: codec: JPEG is not supported':
case 'Error: 403':
case 'Error: 404':
case 'Error: RTSP error: 404 Not Found':
case 'Error: Failed to get stream.':
重新設計的錯誤結構:
json
[
{
"type": "https://example.com/problems/access-denied",
"title": "Access Denied",
"status": 403,
"detail": "Client does not have access rights to the content.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/streaming-destroying",
"title": "Streaming Destroying",
"status": 500,
"detail": "The streaming session is being destroyed due to an internal error.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/internal-server-error",
"title": "Internal Server Error",
"status": 500,
"detail": "The server encountered an internal error.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/bad-request",
"title": "Bad Request",
"status": 400,
"detail": "The request is invalid or cannot be served.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/destination-unreachable",
"title": "Destination Unreachable",
"status": 404,
"detail": "The destination server is unreachable.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/continuous-play-failed",
"title": "Continuous Play Failed",
"status": 500,
"detail": "Continuous play of the stream failed due to an internal error.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/codec-not-supported",
"title": "Codec Not Supported",
"status": 415,
"detail": "The requested codec H265 is not supported.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/codec-not-supported",
"title": "Codec Not Supported",
"status": 415,
"detail": "The requested codec HEVC is not supported.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/codec-not-supported",
"title": "Codec Not Supported",
"status": 415,
"detail": "The requested codec JPEG is not supported.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/video-codec-changed",
"title": "Video Codec Changed",
"status": 409,
"detail": "The video codec has been changed.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/codec-changed",
"title": "Codec Changed",
"status": 409,
"detail": "The codec H264 has been changed.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/codec-changed",
"title": "Codec Changed",
"status": 409,
"detail": "The codec HEVC has been changed.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/unsupported-mime-type",
"title": "Unsupported MIME Type",
"status": 415,
"detail": "The requested MIME type is not supported.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/stream-not-found",
"title": "Stream Not Found",
"status": 404,
"detail": "The requested stream could not be found.",
"instance": "/streams/12345"
},
{
"type": "https://example.com/problems/failed-to-get-stream",
"title": "Failed to Get Stream",
"status": 500,
"detail": "Failed to get the stream due to an internal error.",
"instance": "/streams/12345"
}
]
OpenAPI 3.1 示例
以下是使用 OpenAPI 3.1 規範描述這些錯誤的示例:
yaml
openapi: 3.1.0
info:
title: RTSP Client API
version: 1.0.0
components:
schemas:
Problem:
type: object
properties:
type:
type: string
format: uri
title:
type: string
status:
type: integer
detail:
type: string
instance:
type: string
format: uri-reference
required:
- type
- title
paths:
/streams/{streamId}:
get:
summary: Get Stream
parameters:
- name: streamId
in: path
required: true
schema:
type: string
responses:
'200':
description: Successful response
'400':
description: Bad Request
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/bad-request
title: Bad Request
status: 400
detail: The request is invalid or cannot be served.
instance: /streams/12345
'403':
description: Access Denied
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/access-denied
title: Access Denied
status: 403
detail: Client does not have access rights to the content.
instance: /streams/12345
'404':
description: Stream Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/stream-not-found
title: Stream Not Found
status: 404
detail: The requested stream could not be found.
instance: /streams/12345
'409':
description: Codec Changed
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/codec-changed
title: Codec Changed
status: 409
detail: The codec H264 has been changed.
instance: /streams/12345
'415':
description: Unsupported Media Type
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/codec-not-supported
title: Codec Not Supported
status: 415
detail: The requested codec H265 is not supported.
instance: /streams/12345
'500':
description: Internal Server Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
example:
type: https://example.com/problems/internal-server-error
title: Internal Server Error
status: 500
detail: The server encountered an internal error.
instance: /streams/12345