Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Default Error Responses #198

Merged
merged 2 commits into from
Oct 26, 2023
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: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,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