SUI-Components / sui

Monorepo for SUI (Simple User Interface) packages.
169 stars 33 forks source link

feat(packages/sui-decorators): Create AsyncInlineError decorator #1746

Closed oriolpuig closed 2 weeks ago

oriolpuig commented 5 months ago

Description

Frontend Tech Community has agreed to create, use, and standardize the @AsyncInlineError() decorator. It will improve our code readability.

This decorator catch-all method errors and each method instead of return a value, will return a tuple like [error, response]. So, with this decorator a method using it will never fail.

On this PR, we provide:


@AsyncInlineError()
function execute() {
  if(error) {
    throw new Error('this is not ok')
  }
  return 'this is ok'
}

const response = execute()
const [error, result] = response

Related Issue

Example

Client test ✅

image

Server test ✅

image