update [flathub] error handling (#6185)

This commit is contained in:
chris48s
2021-02-14 18:44:35 +00:00
committed by GitHub
parent 0eee9027fc
commit 106f72524c
2 changed files with 6 additions and 21 deletions

View File

@@ -1,7 +1,6 @@
'use strict'
const Joi = require('joi')
const { InvalidResponse, NotFound } = require('..')
const { renderVersionBadge } = require('../version')
const { BaseJsonService } = require('..')
@@ -25,24 +24,10 @@ module.exports = class Flathub extends BaseJsonService {
static defaultBadgeData = { label: 'flathub' }
async handle({ packageName }) {
try {
const data = await this._requestJson({
schema,
url: `https://flathub.org/api/v1/apps/${encodeURIComponent(
packageName
)}`,
})
return renderVersionBadge({ version: data.currentReleaseVersion })
} catch (error) {
if (error instanceof InvalidResponse) {
// Note the 'not found' response from Flathub is:
// status code = 200,
// body = empty
throw new NotFound({
prettyMessage: `${packageName} not found`,
})
}
throw error
}
const data = await this._requestJson({
schema,
url: `https://flathub.org/api/v1/apps/${encodeURIComponent(packageName)}`,
})
return renderVersionBadge({ version: data.currentReleaseVersion })
}
}

View File

@@ -22,4 +22,4 @@ t.create('Flathub (valid)')
t.create('Flathub (not found)')
.get('/not.a.package.json')
.expectBadge({ label: 'flathub', message: 'not.a.package not found' })
.expectBadge({ label: 'flathub', message: 'not found' })