Files
accounted/app/api/salary/tax-tables/status/route.ts
T
Mattsson e11f70b347 Bug/gh issues fiz (#1103)
* refactor: optimize page loading and data fetching

* fix: resolve recurring production runtime errors

* feat: add MCP company and customer updates

* fix: handle year-end tax adjustments

* feat: harden annual report compliance

* fix: expand invoice logo and font support

* fix: sanitize API route error responses

* fix: sanitize user-facing error messages

* feat: persist onboarding and tax assessment notices

* fix: reduce cloud backup audit churn

* feat: refine invoice editor layout

* fix: show saved tax adjustments in INK2

* fix: complete annual report API mappings

* docs: record operational safeguards and decisions

* fix: harden annual report review findings

* fix: adjust column span for description based on VAT registration

* New css class name
2026-07-21 23:00:15 +02:00

39 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { fetchTaxTableRates, TaxTableUnavailableError } from '@/lib/salary/tax-tables'
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
/**
* Probe Skatteverket's open data API to confirm tax tables are reachable.
* Used by the salary settings page to surface that fetching is automatic.
*/
export const GET = withRouteContext('salary.tax_tables.status', async (request) => {
const { searchParams } = new URL(request.url)
const year = parseInt(searchParams.get('year') || String(new Date().getFullYear()))
try {
const { source } = await fetchTaxTableRates(year, 30, 1)
return NextResponse.json({
data: {
year,
source,
reachable: source === 'api',
checkedAt: new Date().toISOString(),
},
})
} catch (err) {
if (err instanceof TaxTableUnavailableError) {
return NextResponse.json({
data: {
year,
source: 'unavailable' as const,
reachable: false,
checkedAt: new Date().toISOString(),
message: getUserErrorMessage(err),
},
})
}
throw err
}
})