Added appropriate HTTP errors to REST repository methods

This commit is contained in:
Christopher Allford 2020-10-01 15:37:58 -07:00
parent f8574bed56
commit cfa20570c1
4 changed files with 16 additions and 1 deletions

View File

@ -81,7 +81,7 @@ export class Setting extends Model {
*
* @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.

View File

@ -13,6 +13,9 @@ function restCreate( httpClient: HTTPClient ): CreateFn< SimpleProductRepository
regular_price: properties.regularPrice,
},
);
if ( response.statusCode >= 400 ) {
throw response;
}
return Promise.resolve( new SimpleProduct( {
id: response.data.id,

View File

@ -6,6 +6,9 @@ import { ListsSettingGroups, SettingGroupRepositoryParams } from '../../../model
function restList( httpClient: HTTPClient ): ListFn< SettingGroupRepositoryParams > {
return async () => {
const response = await httpClient.get( '/wc/v3/settings' );
if ( response.statusCode >= 400 ) {
throw response;
}
const list: SettingGroup[] = [];
for ( const raw of response.data ) {

View File

@ -16,6 +16,9 @@ import {
function restList( httpClient: HTTPClient ): ListChildFn< SettingRepositoryParams > {
return async ( parent ) => {
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID );
if ( response.statusCode >= 400 ) {
throw response;
}
const list: Setting[] = [];
for ( const raw of response.data ) {
@ -37,6 +40,9 @@ function restList( httpClient: HTTPClient ): ListChildFn< SettingRepositoryParam
function restRead( httpClient: HTTPClient ): ReadChildFn< SettingRepositoryParams > {
return async ( parent, id ) => {
const response = await httpClient.get( '/wc/v3/settings/' + parent.settingGroupID + '/' + id );
if ( response.statusCode >= 400 ) {
throw response;
}
return Promise.resolve( new Setting( {
id: response.data.id,
@ -56,6 +62,9 @@ function restUpdate( httpClient: HTTPClient ): UpdateChildFn< SettingRepositoryP
'/wc/v3/settings/' + parent.settingGroupID + '/' + id,
params,
);
if ( response.statusCode >= 400 ) {
throw response;
}
return Promise.resolve( new Setting( {
id: response.data.id,