mirror of
https://github.com/oceanprotocol/ens-proxy.git
synced 2024-12-02 05:57:34 +01:00
Updating responses and error handling
This commit is contained in:
parent
ca7ea96dfa
commit
398e147f23
@ -9,11 +9,11 @@ export default async function getEnsAddress(
|
|||||||
const ensName = request.query.name
|
const ensName = request.query.name
|
||||||
const provider = await getProvider()
|
const provider = await getProvider()
|
||||||
const address = await provider.resolveName(ensName)
|
const address = await provider.resolveName(ensName)
|
||||||
if (!address) throw `No address found for "${ensName}"`
|
if (!address) throw `No address found for ${ensName}`
|
||||||
|
|
||||||
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
||||||
response.status(200).send(address)
|
response.status(200).send({ address })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
response.status(500).send(`${error}`)
|
response.send({ error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ export default async function nameApi(
|
|||||||
const name = await getEnsName(accountId)
|
const name = await getEnsName(accountId)
|
||||||
|
|
||||||
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
||||||
response.status(200).send(name)
|
response.status(200).send({ name })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
response.status(500).send(`${error}`)
|
response.send({ error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ export async function getEnsProfile(accountId: string): Promise<Profile> {
|
|||||||
const links: ProfileLink[] = records.filter((record) =>
|
const links: ProfileLink[] = records.filter((record) =>
|
||||||
linkKeys.includes(record.key)
|
linkKeys.includes(record.key)
|
||||||
)
|
)
|
||||||
console.log('getEnsAvatar(name)', getEnsAvatar(name))
|
|
||||||
|
|
||||||
const profile: Profile = {
|
const profile: Profile = {
|
||||||
name,
|
name,
|
||||||
@ -66,8 +65,8 @@ export default async function EnsProfileApi(
|
|||||||
const profile = await getEnsProfile(accountId)
|
const profile = await getEnsProfile(accountId)
|
||||||
|
|
||||||
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
||||||
response.status(200).send(profile)
|
response.status(200).send({ profile })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
response.status(500).send(`${error}`)
|
response.send({ error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ export async function getEnsTextRecords(
|
|||||||
const records = []
|
const records = []
|
||||||
const provider = await getProvider()
|
const provider = await getProvider()
|
||||||
const resolver = await provider.getResolver(ensName)
|
const resolver = await provider.getResolver(ensName)
|
||||||
|
if (!resolver) throw `No text records found for ${ensName}`
|
||||||
|
|
||||||
for (let index = 0; index < texts?.length; index++) {
|
for (let index = 0; index < texts?.length; index++) {
|
||||||
const key = texts[index]
|
const key = texts[index]
|
||||||
@ -36,8 +37,8 @@ export default async function ensTextApi(
|
|||||||
const records = await getEnsTextRecords(ensName)
|
const records = await getEnsTextRecords(ensName)
|
||||||
|
|
||||||
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
||||||
response.status(200).send(records)
|
response.status(200).send({ records })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
response.status(500).send(`${error}`)
|
response.send({ error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user