|
7 | 7 | buildNextPageUrl, |
8 | 8 | getLastImageMarker, |
9 | 9 | validateGlanceService, |
10 | | - mapResponseToTRPCError, |
| 10 | + mapErrorResponseToTRPCError, |
11 | 11 | ImageErrorHandlers, |
12 | 12 | handleZodParsingError, |
13 | 13 | wrapError, |
@@ -309,106 +309,106 @@ describe("imageHelpers", () => { |
309 | 309 | }) |
310 | 310 | }) |
311 | 311 |
|
312 | | - describe("mapResponseToTRPCError", () => { |
313 | | - it("should map 400 status to BAD_REQUEST", () => { |
314 | | - const response = { status: 400, statusText: "Bad Request" } |
| 312 | + describe("mapErrorResponseToTRPCError", () => { |
| 313 | + it("should map 400 status BAD_REQUEST", () => { |
| 314 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 400, message: "Bad Request" } |
315 | 315 | const context = { operation: "create image", imageId: "image-123" } |
316 | 316 |
|
317 | | - const error = mapResponseToTRPCError(response, context) |
| 317 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
318 | 318 |
|
319 | 319 | expect(error.code).toBe("BAD_REQUEST") |
320 | 320 | expect(error.message).toBe("Failed to create image image: image-123") |
321 | 321 | }) |
322 | 322 |
|
323 | | - it("should map 403 status to FORBIDDEN", () => { |
324 | | - const response = { status: 403, statusText: "Forbidden" } |
| 323 | + it("should map 403 status FORBIDDEN", () => { |
| 324 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 403, message: "Forbidden" } |
325 | 325 | const context = { operation: "delete image", imageId: "image-123" } |
326 | 326 |
|
327 | | - const error = mapResponseToTRPCError(response, context) |
| 327 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
328 | 328 |
|
329 | 329 | expect(error.code).toBe("FORBIDDEN") |
330 | 330 | expect(error.message).toBe("Access forbidden - cannot delete image image: image-123") |
331 | 331 | }) |
332 | 332 |
|
333 | | - it("should map 404 status to NOT_FOUND", () => { |
334 | | - const response = { status: 404, statusText: "Not Found" } |
| 333 | + it("should map 404 status NOT_FOUND", () => { |
| 334 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 404, message: "Not Found" } |
335 | 335 | const context = { operation: "get image", imageId: "image-123" } |
336 | 336 |
|
337 | | - const error = mapResponseToTRPCError(response, context) |
| 337 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
338 | 338 |
|
339 | 339 | expect(error.code).toBe("NOT_FOUND") |
340 | 340 | expect(error.message).toBe("Image not found image: image-123") |
341 | 341 | }) |
342 | 342 |
|
343 | 343 | it("should map 404 status with member info", () => { |
344 | | - const response = { status: 404, statusText: "Not Found" } |
| 344 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 404, message: "Not Found" } |
345 | 345 | const context = { operation: "get member", imageId: "image-123", memberId: "member-456" } |
346 | 346 |
|
347 | | - const error = mapResponseToTRPCError(response, context) |
| 347 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
348 | 348 |
|
349 | 349 | expect(error.code).toBe("NOT_FOUND") |
350 | 350 | expect(error.message).toBe("Image or member not found image: image-123, member: member-456") |
351 | 351 | }) |
352 | 352 |
|
353 | | - it("should map 409 status to CONFLICT", () => { |
354 | | - const response = { status: 409, statusText: "Conflict" } |
| 353 | + it("should map 409 status CONFLICT to TRPC Error", () => { |
| 354 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 409, message: "Conflict" } |
355 | 355 | const context = { operation: "update image", imageId: "image-123" } |
356 | 356 |
|
357 | | - const error = mapResponseToTRPCError(response, context) |
| 357 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
358 | 358 |
|
359 | 359 | expect(error.code).toBe("CONFLICT") |
360 | 360 | expect(error.message).toBe("Conflict - update image image: image-123") |
361 | 361 | }) |
362 | 362 |
|
363 | | - it("should map 413 status to PAYLOAD_TOO_LARGE", () => { |
364 | | - const response = { status: 413, statusText: "Payload Too Large" } |
| 363 | + it("should map 413 status PAYLOAD_TOO_LARGE", () => { |
| 364 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 413, message: "Payload Too Large" } |
365 | 365 | const context = { operation: "upload image", imageId: "image-123" } |
366 | 366 |
|
367 | | - const error = mapResponseToTRPCError(response, context) |
| 367 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
368 | 368 |
|
369 | 369 | expect(error.code).toBe("PAYLOAD_TOO_LARGE") |
370 | 370 | expect(error.message).toBe("Request entity too large image: image-123") |
371 | 371 | }) |
372 | 372 |
|
373 | | - it("should map 415 status to BAD_REQUEST", () => { |
374 | | - const response = { status: 415, statusText: "Unsupported Media Type" } |
| 373 | + it("should map 415 status BAD_REQUEST", () => { |
| 374 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 415, message: "Unsupported Media Type" } |
375 | 375 | const context = { operation: "upload image", imageId: "image-123" } |
376 | 376 |
|
377 | | - const error = mapResponseToTRPCError(response, context) |
| 377 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
378 | 378 |
|
379 | 379 | expect(error.code).toBe("BAD_REQUEST") |
380 | 380 | expect(error.message).toBe("Unsupported media type image: image-123") |
381 | 381 | }) |
382 | 382 |
|
383 | | - it("should map unknown status to INTERNAL_SERVER_ERROR", () => { |
384 | | - const response = { status: 500, statusText: "Internal Server Error" } |
| 383 | + it("should map unknown status INTERNAL_SERVER_ERROR", () => { |
| 384 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 500, message: "Internal Server Error" } |
385 | 385 | const context = { operation: "create image" } |
386 | 386 |
|
387 | | - const error = mapResponseToTRPCError(response, context) |
| 387 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
388 | 388 |
|
389 | 389 | expect(error.code).toBe("INTERNAL_SERVER_ERROR") |
390 | 390 | expect(error.message).toBe("Failed to create image: Internal Server Error") |
391 | 391 | }) |
392 | 392 |
|
393 | | - it("should handle missing statusText", () => { |
394 | | - const response = { status: 500 } |
| 393 | + it("should handle missing status text", () => { |
| 394 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 500, message: "" } |
395 | 395 | const context = { operation: "create image" } |
396 | 396 |
|
397 | | - const error = mapResponseToTRPCError(response, context) |
| 397 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
398 | 398 |
|
399 | 399 | expect(error.code).toBe("INTERNAL_SERVER_ERROR") |
400 | 400 | expect(error.message).toBe("Failed to create image: Unknown error") |
401 | 401 | }) |
402 | 402 |
|
403 | 403 | it("should include additional info when provided", () => { |
404 | | - const response = { status: 400, statusText: "Bad Request" } |
| 404 | + const errorResponse = { name: "SignalOpenstackApiError", statusCode: 400, message: "Bad Request" } |
405 | 405 | const context = { |
406 | 406 | operation: "create image", |
407 | 407 | imageId: "image-123", |
408 | 408 | additionalInfo: "Invalid disk format", |
409 | 409 | } |
410 | 410 |
|
411 | | - const error = mapResponseToTRPCError(response, context) |
| 411 | + const error = mapErrorResponseToTRPCError(errorResponse, context) |
412 | 412 |
|
413 | 413 | expect(error.message).toBe("Failed to create image image: image-123 - Invalid disk format") |
414 | 414 | }) |
|
0 commit comments