Skip to content

Commit

Permalink
fix: faults with action return error type change - use createActionEr…
Browse files Browse the repository at this point in the history
…ror instead
  • Loading branch information
JohanHjelsethStorstad committed Oct 18, 2024
1 parent 844fb2a commit 6b0b1ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app/api/apiHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'server-only'
import { Session } from '@/auth/Session'
import { ServerError, Smorekopp } from '@/services/error'
import type { ActionErrorCode } from '@/actions/Types'
import type { ErrorCode } from '@/services/error'
import type { SessionNoUser } from '@/auth/Session'
import type { ServiceMethod } from '@/services/ServiceTypes'

Expand Down Expand Up @@ -110,7 +110,7 @@ export function apiHandler<
)
}

function createApiErrorRespone(errorCode: ActionErrorCode, message: string) {
function createApiErrorRespone(errorCode: ErrorCode, message: string) {
return new Response(JSON.stringify({
errorCode,
message
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useActionCall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'
import { useState, useEffect } from 'react'
import type { ActionReturn, ActionReturnError } from '@/actions/Types'
import { createActionError } from '@/actions/error'

/**
* You sometimes want to call a server action that reads from the client. This hook helps with that.
Expand Down Expand Up @@ -32,7 +33,7 @@ export default function useActionCall<
setRes({ data: null, error: result })
}
}).catch(() => {
setRes({ data: null, error: { success: false, errorCode: 'UNKNOWN ERROR' } })
setRes({ data: null, error: createActionError('UNKNOWN ERROR', 'An unknown error occured') })
})
}, [action])

Expand Down
9 changes: 2 additions & 7 deletions src/jwt/parseJWTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { JWT_ISSUER } from '@/auth/ConfigVars'
import type { OmegaJWTAudience } from '@/auth/Types'
import type { ActionReturn } from '@/actions/Types'
import type { OmegaId } from '@/services/omegaid/Types'
import { createActionError } from '@/actions/error'

/**
* Parses a JSON Web Token (JWT) and verifies its signature using the provided public key.
Expand All @@ -19,13 +20,7 @@ export async function parseJWT(token: string, publicKey: string, timeOffset: num
// TODO: This only works in safari and firefox :///

function invalidJWT(message?: string): ActionReturn<OmegaId> {
return {
success: false,
errorCode: 'JWT INVALID',
error: message ? [{
message
}] : []
}
return createActionError('JWT INVALID', message || 'Ugyldig QR kode')
}

if (timeOffset < 0) {
Expand Down

0 comments on commit 6b0b1ca

Please sign in to comment.