Skip to content

Commit

Permalink
feat: added 410 response code (#620)
Browse files Browse the repository at this point in the history
* feat: added 410 response code
  • Loading branch information
RaduPetreTarean authored May 13, 2024
1 parent f8a5ac2 commit c0b877b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
13 changes: 13 additions & 0 deletions components/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ responses:
content:
application/vnd.api+json:
schema: { $ref: '#/schemas/ErrorDocument' }

'410':
description: 'Gone: The requested resource has been discontinued and is no longer available.'
headers:
snyk-version-requested: { $ref: '#/headers/VersionRequestedResponseHeader' }
snyk-version-served: { $ref: '#/headers/VersionServedResponseHeader' }
snyk-request-id: { $ref: '#/headers/RequestIdResponseHeader' }
snyk-version-lifecycle-stage: { $ref: '#/headers/VersionStageResponseHeader' }
deprecation: { $ref: '#/headers/DeprecationHeader' }
sunset: { $ref: '#/headers/SunsetHeader' }
content:
application/vnd.api+json:
schema: { $ref: '#/schemas/ErrorDocument' }

'500':
description: 'Internal Server Error: An error was encountered while attempting to process the request.'
Expand Down
4 changes: 4 additions & 0 deletions docs/standards/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ A not found status code & error response must be returned if the requested resou

A conflict status code & error response must be returned if a requested _write_ action cannot be performed because it collides with some constraint (e.g. a unique constraint violation). This status code is also useful when processing idempotent requests which currently are not supported as a part of the Snyk API.

### 410 - Gone

A Gone status code and error response should be sent when a resource that used to be available on the server no longer exists and there's no redirection provided. This tells the user that the server used to have this resource, but it has been permanently removed and isn't coming back. For example, if an old version of an API is phased out and removed, any attempt to access it should result in a 410 Gone response, clearly indicating that the resource is no longer available.

### 429 - Too Many Requests

A too many requests status code & error response must be returned if the requester has exceeded their request quota for some given time period.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ const valid4xxCodes = new ResponseRule({
name: "valid 4xx status codes",
matches: (response) => response.statusCode.startsWith("4"),
rule: (responseAssertions) => {
const allowed4xxStatusCodes = ["400", "401", "403", "404", "409", "429"];
const allowed4xxStatusCodes = [
"400",
"401",
"403",
"404",
"409",
"410",
"429",
];
responseAssertions.added(
"support the correct 4xx status codes",
(response) => {
Expand Down
4 changes: 2 additions & 2 deletions src/woollypully/__tests__/checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("checker", () => {
testTimeout,
);

test.each([400, 404, 500])(
test.each([400, 404, 410, 500])(
"fails if apis request responds with %s",
async (status) => {
(axios.default.create as jest.Mock).mockImplementation(() => ({
Expand All @@ -114,7 +114,7 @@ describe("checker", () => {
testTimeout,
);

test.each([400, 404, 500])(
test.each([400, 404, 410, 500])(
"fails if versions request responds with %s",
async (status) => {
(axios.default.create as jest.Mock).mockImplementation(() => ({
Expand Down

0 comments on commit c0b877b

Please sign in to comment.