Files
slm-design/.templates/rest-api/{{name.kebabCase}}-rest-api/lib/{{name.kebabCase}}-rest-api-fetch.ts

15 lines
510 B
TypeScript
Raw Normal View History

2026-08-01 09:31:08 +03:00
import { {{name.pascalCase}}RestApiTransportError } from '../errors'
/**
* Выполняет fetch с явной классификацией transport failure.
*/
export const {{name.camelCase}}RestApiFetch: typeof fetch = async (...params) => {
try {
return await fetch(...params)
} catch (error) {
const code = error instanceof DOMException && error.name === 'AbortError' ? 'REQUEST_TIMEOUT' : 'NETWORK_UNAVAILABLE'
throw new {{name.pascalCase}}RestApiTransportError(code, error)
}
}