Skip to content

Commit

Permalink
Document Default Error Responses (#198)
Browse files Browse the repository at this point in the history
* Document Defalut Error Responses

Include documentation for 500 & 503 responses in default schema definition

This ensures that they get included in the Open API documentation generated.

- chore: update tests to match updated responses

* Clarify Setting of `statusCode` as HTTP Code Always
  • Loading branch information
muya authored Oct 26, 2023
1 parent 6452aaf commit ae70caa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,29 @@ async function fastifyUnderPressure (fastify, opts) {
response: {
200: {
type: 'object',
description: 'Health Check Succeeded',
properties: Object.assign(
{ status: { type: 'string' } },
opts.exposeStatusRoute.routeResponseSchemaOpts
)
},
500: {
type: 'object',
description: 'Error Performing Health Check',
properties: {
message: { type: 'string', description: 'Error message for failure during health check', example: 'Internal Server Error' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 500 }
}
},
503: {
type: 'object',
description: 'Health Check Failed',
properties: {
code: { type: 'string', description: 'Error code associated with the failing check', example: 'FST_UNDER_PRESSURE' },
error: { type: 'string', description: 'Error thrown during health check', example: 'Service Unavailable' },
message: { type: 'string', description: 'Error message to explain health check failure', example: 'Service Unavailable' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 503 }
}
}
}
}),
Expand Down
38 changes: 38 additions & 0 deletions test/statusRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,28 @@ test('Expose status route with additional route options, route schema options',
response: {
200: {
type: 'object',
description: 'Health Check Succeeded',
properties: {
status: { type: 'string' }
}
},
500: {
type: 'object',
description: 'Error Performing Health Check',
properties: {
message: { type: 'string', description: 'Error message for failure during health check', example: 'Internal Server Error' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 500 }
}
},
503: {
type: 'object',
description: 'Health Check Failed',
properties: {
code: { type: 'string', description: 'Error code associated with the failing check', example: 'FST_UNDER_PRESSURE' },
error: { type: 'string', description: 'Error thrown during health check', example: 'Service Unavailable' },
message: { type: 'string', description: 'Error message to explain health check failure', example: 'Service Unavailable' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 503 }
}
}
}
}), 'config not set')
Expand Down Expand Up @@ -166,9 +185,28 @@ test('Expose status route with additional route options, route schema options an
response: {
200: {
type: 'object',
description: 'Health Check Succeeded',
properties: {
status: { type: 'string' }
}
},
500: {
type: 'object',
description: 'Error Performing Health Check',
properties: {
message: { type: 'string', description: 'Error message for failure during health check', example: 'Internal Server Error' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 500 }
}
},
503: {
type: 'object',
description: 'Health Check Failed',
properties: {
code: { type: 'string', description: 'Error code associated with the failing check', example: 'FST_UNDER_PRESSURE' },
error: { type: 'string', description: 'Error thrown during health check', example: 'Service Unavailable' },
message: { type: 'string', description: 'Error message to explain health check failure', example: 'Service Unavailable' },
statusCode: { type: 'number', description: 'Code representing the error. Always matches the HTTP response code.', example: 503 }
}
}
}
}), 'config not set')
Expand Down

0 comments on commit ae70caa

Please sign in to comment.