-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:adobe-rnd/spacecat-shared into rum-…
…apis
- Loading branch information
Showing
11 changed files
with
226 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2023 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { Response } from '@adobe/fetch'; | ||
|
||
/** | ||
* Creates a response with a JSON body. Defaults to 200 status. | ||
* @param {object} body - JSON body. | ||
* @param {number} status - Optional status code. | ||
* @param {object} headers - Optional headers. | ||
* @return {Response} Response. | ||
*/ | ||
export function createResponse(body, status = 200, headers = {}) { | ||
return new Response( | ||
JSON.stringify(body), | ||
{ | ||
headers: { 'content-type': 'application/json; charset=utf-8', ...headers }, | ||
status, | ||
}, | ||
); | ||
} | ||
export function ok(body) { | ||
return createResponse(body, 200); | ||
} | ||
|
||
export function noContent(headers) { | ||
return createResponse('', 204, headers); | ||
} | ||
|
||
export function badRequest(message) { | ||
return createResponse({ message }, 400); | ||
} | ||
|
||
export function notFound(message) { | ||
return createResponse({ message }, 404); | ||
} | ||
|
||
export function internalServerError(message) { | ||
return createResponse({ message }, 500, { | ||
'x-error': `internal server error: ${message}`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.