Added appropriate HTTP errors to REST repository methods
This commit is contained in:
parent
f8574bed56
commit
cfa20570c1
|
@ -81,7 +81,7 @@ export class Setting extends Model {
|
||||||
*
|
*
|
||||||
* @type {Object.<string, string>|null}
|
* @type {Object.<string, string>|null}
|
||||||
*/
|
*/
|
||||||
public readonly options: { [key: string]: string } | null = null;
|
public readonly options: { [key: string]: string } | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default value for the setting.
|
* The default value for the setting.
|
||||||
|
|
|
@ -13,6 +13,9 @@ function restCreate( httpClient: HTTPClient ): CreateFn< SimpleProductRepository
|
||||||
regular_price: properties.regularPrice,
|
regular_price: properties.regularPrice,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
if ( response.statusCode >= 400 ) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve( new SimpleProduct( {
|
return Promise.resolve( new SimpleProduct( {
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
|
|
|
@ -6,6 +6,9 @@ import { ListsSettingGroups, SettingGroupRepositoryParams } from '../../../model
|
||||||
function restList( httpClient: HTTPClient ): ListFn< SettingGroupRepositoryParams > {
|
function restList( httpClient: HTTPClient ): ListFn< SettingGroupRepositoryParams > {
|
||||||
return async () => {
|
return async () => {
|
||||||
const response = await httpClient.get( '/wc/v3/settings' );
|
const response = await httpClient.get( '/wc/v3/settings' );
|
||||||
|
if ( response.statusCode >= 400 ) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
const list: SettingGroup[] = [];
|
const list: SettingGroup[] = [];
|
||||||
for ( const raw of response.data ) {
|
for ( const raw of response.data ) {
|
||||||
|
|
|
@ -16,6 +16,9 @@ import {
|
||||||
function restList( httpClient: HTTPClient ): ListChildFn< SettingRepositoryParams > {
|
function restList( httpClient: HTTPClient ): ListChildFn< SettingRepositoryParams > {
|
||||||
return async ( parent ) => {
|
return async ( parent ) => {
|
||||||
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID );
|
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID );
|
||||||
|
if ( response.statusCode >= 400 ) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
const list: Setting[] = [];
|
const list: Setting[] = [];
|
||||||
for ( const raw of response.data ) {
|
for ( const raw of response.data ) {
|
||||||
|
@ -37,6 +40,9 @@ function restList( httpClient: HTTPClient ): ListChildFn< SettingRepositoryParam
|
||||||
function restRead( httpClient: HTTPClient ): ReadChildFn< SettingRepositoryParams > {
|
function restRead( httpClient: HTTPClient ): ReadChildFn< SettingRepositoryParams > {
|
||||||
return async ( parent, id ) => {
|
return async ( parent, id ) => {
|
||||||
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID + '/' + id );
|
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID + '/' + id );
|
||||||
|
if ( response.statusCode >= 400 ) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve( new Setting( {
|
return Promise.resolve( new Setting( {
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
|
@ -56,6 +62,9 @@ function restUpdate( httpClient: HTTPClient ): UpdateChildFn< SettingRepositoryP
|
||||||
'/wc/v3/settings/' + parent.settingGroupID + '/' + id,
|
'/wc/v3/settings/' + parent.settingGroupID + '/' + id,
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
|
if ( response.statusCode >= 400 ) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve( new Setting( {
|
return Promise.resolve( new Setting( {
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
|
|
Loading…
Reference in New Issue