Skip to content

Commit

Permalink
ar(fix) [DPCP-44] [DPCP-24]: Nyx Timeout on Hydration, Audio Player d…
Browse files Browse the repository at this point in the history
…isable au… (#26)

* ar(fix) DPCP-44-24: Nyx Timeout on Hydration, Audio Player disable autoPlay.

* ar(fix) DPCP-44-24: Nyx Timeout on Hydration, Audio Player disable autoPlay.

* ar(fix) DPCP-44-24: Nyx Timeout on Hydration, Audio Player disable autoPlay.

* ar(fix) DPCP-44-24: Nyx Timeout on Hydration, Audio Player disable autoPlay.

* ar(fix) DPCP-44-24: Nyx Timeout on Hydration, Audio Player disable autoPlay.
  • Loading branch information
angeloreale authored Aug 5, 2024
1 parent 463af32 commit c562f2b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
17 changes: 17 additions & 0 deletions lib/model/interfaces/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
// to-do: let's make an @helpers alias!
// import { NexusDB } from "@controller"

export async function fetchWithTimeout(resource: string, options: any) {
const { timeout = 3000 } = options;

const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);

const promise = await fetch(resource, {
...options,
signal: controller.signal,
});

const response = promise;
clearTimeout(id);

return response;
}

export const patience = async (sleep = 1000): Promise<unknown> => {
// if (NexusDB && !NexusDB.oplog?.length) {
// if (NexusDB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// rm-connector.ts
// to-do: use prisma for graph type
import type { ICard } from '@dreampipcom/oneiros';

import { cookies } from 'next/headers';
import { fetchWithTimeout } from '../../../helpers';
// const CHARS = `
// query {
// characters() {
Expand Down Expand Up @@ -32,7 +32,7 @@ async function fetchREPL({ paramsStr, method, listings }: any) {
const cookieStore = cookies();
const cookieString = cookieStore.toString();
const payload = JSON.stringify({ listings });
const req = await fetch(`${process.env.API_HOST}/api/v1/user${paramsStr}`, {
const req = await fetchWithTimeout(`${process.env.API_HOST}/api/v1/user${paramsStr}`, {
method,
headers: {
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// rm-connector.ts
// to-do: use prisma for graph type
import type { ICard } from '@dreampipcom/oneiros';
import { fetchWithTimeout } from '../../../helpers';
// const CHARS = `
// query {
// characters() {
Expand All @@ -26,7 +27,7 @@ import type { ICard } from '@dreampipcom/oneiros';
async function fetchREPL({ paramsStr }: any) {
// to-do: might be worth hardcoding the api in case too many middleware requests are billed
try {
const response = await fetch(`${process.env.API_HOST}/api/v1/public${paramsStr}`, {
const response = await fetchWithTimeout(`${process.env.API_HOST}/api/v1/public${paramsStr}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion lib/model/interfaces/services/rickmorty/rm-connector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// rm-connector.ts
// to-do: use prisma for graph type
import type { INCharacter } from '@types';
import { fetchWithTimeout } from '../../helpers';
const CHARS = `
query {
characters() {
Expand All @@ -25,7 +26,7 @@ query {

async function fetchGraphQL(query: string) {
try {
return fetch(`https://rickandmortyapi.com/graphql`, {
return fetchWithTimeout(`https://rickandmortyapi.com/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prepare": "husky"
},
"dependencies": {
"@dreampipcom/oneiros": "0.0.12",
"@dreampipcom/oneiros": "0.0.14",
"@sentry/nextjs": "7.118.0",
"next": "14.2.4",
"react": "18",
Expand Down

0 comments on commit c562f2b

Please sign in to comment.