{"id":17366765,"url":"https://github.com/vojvodicn23/http-handler","last_synced_at":"2026-02-15T01:33:56.525Z","repository":{"id":257205540,"uuid":"857661584","full_name":"vojvodicn23/http-handler","owner":"vojvodicn23","description":"The http handler library for Angular","archived":false,"fork":false,"pushed_at":"2025-03-05T11:33:13.000Z","size":143,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-23T11:19:13.402Z","etag":null,"topics":["angular","error-handling","fallback","handler","http","http-client","loading"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vojvodicn23.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-15T09:07:19.000Z","updated_at":"2025-03-05T11:33:17.000Z","dependencies_parsed_at":"2024-09-15T09:52:49.777Z","dependency_job_id":"9ede0afd-8fb2-44a2-9698-8577b9608ba0","html_url":"https://github.com/vojvodicn23/http-handler","commit_stats":null,"previous_names":["vojvodicn23/http-handler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vojvodicn23/http-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojvodicn23%2Fhttp-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojvodicn23%2Fhttp-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojvodicn23%2Fhttp-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojvodicn23%2Fhttp-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vojvodicn23","download_url":"https://codeload.github.com/vojvodicn23/http-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vojvodicn23%2Fhttp-handler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29464229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T01:01:38.065Z","status":"ssl_error","status_checked_at":"2026-02-15T01:01:23.809Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","error-handling","fallback","handler","http","http-client","loading"],"created_at":"2024-10-15T22:04:45.066Z","updated_at":"2026-02-15T01:33:56.509Z","avatar_url":"https://github.com/vojvodicn23.png","language":"TypeScript","readme":"# Angular HTTP Handler\n\n## Introduction\n\nAn Angular library for handling HTTP requests with loading state management, error handling, retry logic, and fallback values.\nSupported Angular versions: 15, 16, 17, 18, 19.\n\n## Features\n\n- Automatically sets loading state during HTTP requests\n- Handles errors with an optional error handler\n- Supports retry logic for failed requests\n- Provides a fallback value when the request fails\n- Provides a global loading indicator\n- Provides a global request count\n\n## Installation\n\nTo install the library, run the following command:\n\n```bash\nnpm install angular-http-handler\n```\n\n\n## Usage\n\nIn your Angular component, you can apply the handle function to any HTTP request.\nHere's an example using HttpClient:\n```typescript\nimport { HttpClient } from '@angular/common/http';\nimport { Component, inject, OnInit } from '@angular/core';\nimport { handle } from 'angular-http-handler';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\nexport class AppComponent implements OnInit {\n  private apiUrl = 'YOUR API URL';\n  http = inject(HttpClient);\n\n  loading = signal(false);\n  response: any[] = [];\n\n  ngOnInit(): void {\n    this.http.get\u003cany[]\u003e(this.apiUrl).pipe(\n      handle(\n        (response) =\u003e {\n          this.response = response;\n          console.log(response);\n        },\n        (loading) =\u003e { // OPTIONAL - loading indicator\n          this.loading.set(loading);\n          console.log(loading);\n        },\n        [], // OPTIONAL - custom fallback value\n        (error) =\u003e { // OPTIONAL - custom error handler\n            console.log(error);\n        }, \n        2, // OPTIONAL - retry count\n        1000, // OPTIONAL - retry delay\n      )\n    ).subscribe();\n  }\n}\n```\n\n### API\nThe `handle` function manages HTTP requests with loading state, error handling and retry.\nParameters:\n\n- dataSetter: (response: T) =\u003e void\nFunction to set the data when the request succeeds (e.g., this.data = response).\n\n- loadingSetter?: (loading: boolean) =\u003e void\nFunction to set the loading state (e.g., this.loading = loading).\n\n- fallbackValue?: any\nValue that will be returned in case of error.\n\n- errorHandler?: (error: HttpErrorResponse) =\u003e void\nOptional function to handle errors (e.g., console.error(error)).\n\n- retryCount?: number\nNumber of retries for failed requests. Defaults to 0.\n\n- retryDelay?: number\nDelay between retries in milliseconds.\n\n- Returns\nAn Observable\u003cT\u003e that handles the request, error, retry.\n\n\n## Configuration (Optional)\n\nIf you want to define custom default parameters you should do it in your root component before any http call.\n- The `defaultErrorHandler` set default error handler for every request wrapped by handler. In case custom error handler is passed as a parameter to handle function it will overwrite the default one.\n- The `defaultRetryCount` and `defaultRetryDelay` set default number of retry in case of error and time between the calls.\n```typescript\nimport { HttpErrorResponse } from '@angular/common/http';\nimport { Component, OnInit } from '@angular/core';\nimport { configureHandler } from 'angular-http-handler';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\nexport class AppComponent implements OnInit {\n\n  ngOnInit(): void {\n\n    configureHandler({\n      defaultErrorHandler: (error: HttpErrorResponse) =\u003e {\n        console.log('deafult handler', error);\n      },\n      defaultRetryCount: 0,\n      defaultRetryDelay: 0\n    });\n  }\n}\n```\n\n### Fallback Response Behavior\n\nThe `handle` function returns a fallback response in case you define it as a 3rd parameter. In case you do not define it it will remain undefined and it will not trigger dataSetter function. \n\n## Aditional Options\n\n### `pendingRequestsCount()`\nThis function returns an Observable\u003cnumber\u003e that emits the total number of pending requests. It helps track how many requests wrapped by handler are still in progress.\n```typescript\nimport { Component, OnDestroy, OnInit } from '@angular/core';\nimport { pendingRequestsCount } from 'angular-http-handler';\nimport { Subscription } from 'rxjs';\n\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\nexport class AppComponent implements OnInit, OnDestroy {\n\n  subs = new Subscription;\n\n  ngOnInit(): void {\n\n    this.subs = pendingRequestsCount().subscribe(count =\u003e {\n      console.log('Pending request count: ', count);\n    });\n  }\n\n  ngOnDestroy(): void {\n    this.subs.unsubscribe();\n  }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojvodicn23%2Fhttp-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvojvodicn23%2Fhttp-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvojvodicn23%2Fhttp-handler/lists"}