@salsita/react-api

1.0.0 • Public • Published

react-api

Install

Install this package with npm

npm i @salsita/react-api

or yarn

yarn add @salsita/react-api

API

Modules

ApiActions
ApiSelectors

Classes

ApiError

The base class for API errors

BusinessValidationError

The class for business validation error

Constants

HTTP_CONFLICT

The error code for HTTP conflict

Functions

apiReducer(state, action)ApiState

The reducer of the API module

withErrorHandling(saga, ...args)

Wraps saga into try/catch block catching all the ApiErrors and translating them to API_ERROR actions.

withLoadingIndicator(saga, ...args)

Wraps saga into start/stop loading actions

wrapApiCall(call)function

Wraps function with try/catch block to catch all the API errors and translate them to according exceptions.

ApiErrorToast()

A simple component that shows an error toast message

ApiLoader()

A simple component that shows a loading indicator

ApiActions

ApiActions.apiError(errorType, errorReason) ⇒ Action

Saves API error

Kind: static method of ApiActions

Param Type Description
errorType string Type of the error
errorReason string Reason of the error

ApiActions.startLoading() ⇒ Action

Sets the global loading indicator on

Kind: static method of ApiActions

ApiActions.stopLoading() ⇒ Action

Sets the global loading indicator off

Kind: static method of ApiActions

ApiSelectors

ApiSelectors.getError(state) ⇒ string | null

Returns the latest API error type

Kind: static method of ApiSelectors
Returns: string | null - The latest API error type

Param Type Description
state RootState The root state

ApiSelectors.isLoading(state) ⇒ boolean

Returns true if a loading is in progress

Kind: static method of ApiSelectors
Returns: boolean - True if a loading indicator is in progress, false otherwise

Param Type Description
state RootState The root state

ApiError

The base class for API errors

Kind: global class

apiError.constructor(type, reason)

Creates an API error

Kind: instance method of ApiError

Param Type Description
type string Type of the error
reason string Reason of the error

apiError.getReason() ⇒ string

Get the error reason

Kind: instance method of ApiError
Returns: string - The error reason

apiError.getType() ⇒ string

Get the error type

Kind: instance method of ApiError
Returns: string - The error type

BusinessValidationError

The class for business validation error

Kind: global class

businessValidationError.constructor(reason)

Creates a business validation error

Kind: instance method of BusinessValidationError

Param Type Description
reason string The error reason

HTTP_CONFLICT

The error code for HTTP conflict

Kind: global constant

apiReducer(state, action) ⇒ ApiState

The reducer of the API module

Kind: global function

Param Type Description
state ApiState The state of the API module
action Action A redux action

withErrorHandling(saga, ...args)

Wraps saga into try/catch block catching all the ApiErrors and translating them to API_ERROR actions.

Kind: global function

Param Type Description
saga Generator API call saga which may throw an ApiError
...args any Arguments to be passed to the saga

withLoadingIndicator(saga, ...args)

Wraps saga into start/stop loading actions

Kind: global function

Param Type Description
saga Generator A long running saga
...args any Arguments to be passed to the saga

wrapApiCall(call) ⇒ function

Wraps function with try/catch block to catch all the API errors and translate them to according exceptions.

Kind: global function
Returns: function - Wrapped API call function

Param Type Description
call function A function calling an API client and returning promise

ApiErrorToast()

A simple component that shows an error toast message

Kind: global function

ApiLoader()

A simple component that shows a loading indicator

Kind: global function

Readme

Keywords

none

Package Sidebar

Install

npm i @salsita/react-api

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

25.2 kB

Total Files

15

Last publish

Collaborators