Updating responses and error handling

This commit is contained in:
Jamie Hewitt 2022-08-24 16:49:17 +03:00
parent ca7ea96dfa
commit 398e147f23
4 changed files with 10 additions and 10 deletions

View File

@ -9,11 +9,11 @@ export default async function getEnsAddress(
const ensName = request.query.name
const provider = await getProvider()
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.status(200).send(address)
response.status(200).send({ address })
} catch (error) {
response.status(500).send(`${error}`)
response.send({ error })
}
}

View File

@ -20,8 +20,8 @@ export default async function nameApi(
const name = await getEnsName(accountId)
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
response.status(200).send(name)
response.status(200).send({ name })
} catch (error) {
response.status(500).send(`${error}`)
response.send({ error })
}
}

View File

@ -46,7 +46,6 @@ export async function getEnsProfile(accountId: string): Promise<Profile> {
const links: ProfileLink[] = records.filter((record) =>
linkKeys.includes(record.key)
)
console.log('getEnsAvatar(name)', getEnsAvatar(name))
const profile: Profile = {
name,
@ -66,8 +65,8 @@ export default async function EnsProfileApi(
const profile = await getEnsProfile(accountId)
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
response.status(200).send(profile)
response.status(200).send({ profile })
} catch (error) {
response.status(500).send(`${error}`)
response.send({ error })
}
}

View File

@ -17,6 +17,7 @@ export async function getEnsTextRecords(
const records = []
const provider = await getProvider()
const resolver = await provider.getResolver(ensName)
if (!resolver) throw `No text records found for ${ensName}`
for (let index = 0; index < texts?.length; index++) {
const key = texts[index]
@ -36,8 +37,8 @@ export default async function ensTextApi(
const records = await getEnsTextRecords(ensName)
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
response.status(200).send(records)
response.status(200).send({ records })
} catch (error) {
response.status(500).send(`${error}`)
response.send({ error })
}
}