@@ -12,39 +12,22 @@ import { OBPErrorBase, OBPRequestError } from "$lib/obp/errors";
1212 *
1313 * IMPORTANT: Never simplify or hide OBP error messages - show them in full!
1414 */
15+ /**
16+ * Extract error from OBP API response.
17+ * OBP returns: { message: string, code: number }
18+ * If the format doesn't match, surface what we got so the problem is visible.
19+ */
1520function extractOBPError (
1621 data : any ,
1722 response : Response ,
1823) : { code ?: string ; message : string } {
19- // If data is a string, return it directly
20- if ( typeof data === "string" ) {
21- return {
22- message : data || `HTTP ${ response . status } : ${ response . statusText } ` ,
23- } ;
24- }
25-
26- // If data is not an object, return status info
27- if ( ! data || typeof data !== "object" ) {
28- return { message : `HTTP ${ response . status } : ${ response . statusText } ` } ;
24+ if ( data && typeof data === "object" && typeof data . message === "string" ) {
25+ return { code : data . code != null ? String ( data . code ) : undefined , message : data . message } ;
2926 }
3027
31- // Extract code from various possible fields
32- const code = data . code || data . failCode || data . error_code ;
33-
34- // Extract message from various possible fields - NEVER use generic fallback if we have data!
35- const message =
36- data . message ||
37- data . failMsg ||
38- data . error ||
39- data . error_message ||
40- // If we have a code but no message, at least show the code
41- ( code ? `Error code: ${ code } ` : null ) ||
42- // If we have any other data, stringify it to show the full response
43- ( Object . keys ( data ) . length > 0
44- ? JSON . stringify ( data )
45- : `HTTP ${ response . status } : ${ response . statusText } ` ) ;
46-
47- return { code, message } ;
28+ throw new Error (
29+ `Unexpected error format from OBP API (HTTP ${ response . status } ): ${ JSON . stringify ( data ) } ` ,
30+ ) ;
4831}
4932
5033class OBPRequests {
0 commit comments