-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OGUI-1442] Use new PUT endpoint for controlling environment (#2204)
* Update front-end to use the new PUT endpoint for controlling an environment * Update method to accept specified parameters rather than an undescribed object
- Loading branch information
Showing
5 changed files
with
79 additions
and
44 deletions.
There are no files selected for viewing
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,39 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
import {jsonFetch} from './jsonFetch.js'; | ||
|
||
/** | ||
* Build and send a PUT request to a remote endpoint, and extract the response. | ||
* @param {String} endpoint - the remote endpoint to send request to | ||
* @param {RequestInit} options - the request options, see {@see fetch } native function | ||
* @return {Promise<Resolve<Object>.Error<{message: String}>>} resolve with the result of the request or reject with the error message | ||
*/ | ||
export const jsonPut = async (endpoint, options) => { | ||
if (options.body && typeof options.body === 'object') { | ||
options.body = JSON.stringify(options.body); | ||
} | ||
try { | ||
const result = await jsonFetch(endpoint, { | ||
method: 'PUT', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
...options | ||
}); | ||
return result; | ||
} catch (error) { | ||
return Promise.reject({message: error.message || error}); | ||
} | ||
} |