Skip to content

Commit

Permalink
docs: update yaml schema files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Sep 27, 2024
1 parent 23b8d00 commit 33b078e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions public/v1/components/headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ components:
required: false
schema:
type: integer
RetryAfter:
description: The number of seconds remaining until the request of this measurement is available again.
required: true
schema:
type: integer
29 changes: 29 additions & 0 deletions public/v1/components/responses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,35 @@ components:
$ref: 'examples.yaml#/components/examples/getMtrMeasurementResponse'
httpMeasurement:
$ref: 'examples.yaml#/components/examples/getHttpMeasurementResponse'
measurement429:
description: |
If you've exceeded the API rate limit, you'll receive status `429 Too Many Requests` and a body containing more information about the error.
headers:
Retry-After:
$ref: 'headers.yaml#/components/headers/RetryAfter'
content:
application/json:
schema:
type: object
required:
- error
properties:
error:
type: object
required:
- type
- message
properties:
type:
type: string
message:
type: string
examples:
json:
value:
error:
type: too_many_requests
message: Too Many Requests.
probes200:
description: |
A successful request returns status `200 OK` and a body containing a list of all probes currently online and their metadata.
Expand Down
5 changes: 5 additions & 0 deletions public/v1/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ paths:
$ref: 'components/responses.yaml#/components/responses/measurement200'
'404':
$ref: 'components/responses.yaml#/components/responses/404'
'429':
$ref: 'components/responses.yaml#/components/responses/measurement429'
tags:
- Measurements
security:
- {}
- bearerAuth: []
/v1/probes:
get:
summary: List probes currently online
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rate-limiter/rate-limiter-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const getMeasurementRateLimit = async (ctx: ExtendedContext, next: Next)
} catch (error) {
if (error instanceof RateLimiterRes) {
setRateLimitHeaders(ctx, error);
throw createHttpError(429, 'Too Many Requests', { type: 'too_many_requests' });
throw createHttpError(429, 'Too Many Requests.', { type: 'too_many_requests' });
}

throw createHttpError(500);
Expand Down
4 changes: 2 additions & 2 deletions src/measurement/route/get-measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getMeasurementStore } from '../store.js';
import { corsAuthHandler } from '../../lib/http/middleware/cors.js';
import { authenticate } from '../../lib/http/middleware/authenticate.js';
import { getMeasurementRateLimit } from '../../lib/rate-limiter/rate-limiter-get.js';
import createHttpError from 'http-errors';

const store = getMeasurementStore();

Expand All @@ -18,8 +19,7 @@ const handle = async (ctx: ParameterizedContext<DefaultState, DefaultContext & R
const result = await store.getMeasurementString(id);

if (!result) {
ctx.status = 404;
return;
throw createHttpError(404, `Couldn't find the requested item.`, { type: 'not_found' });
}

ctx.type = 'application/json';
Expand Down

0 comments on commit 33b078e

Please sign in to comment.