Skip to content

Commit 56c8f20

Browse files
committed
changing content type for authentication failure
1 parent e3e9c01 commit 56c8f20

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/controllers/auth_controller.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ class AuthController < ApplicationController
44
ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash'.freeze
55

66
def failure
7-
render json: 'Authentication failed', status: :unauthorized
7+
error = {
8+
errors: [
9+
{
10+
status: '401',
11+
title: 'Authentication failed',
12+
detail: 'Authentication failed'
13+
}
14+
]
15+
}
16+
17+
render json: error, status: :unauthorized, content_type: JSONAPI::MEDIA_TYPE
818
end
919

1020
def callback

spec/requests/auth_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
get '/auth/failure'
5353

5454
expect(response).to have_http_status(:unauthorized)
55-
expect(response.parsed_body).to eq('Authentication failed')
55+
expect(response.content_type).to start_with(JSONAPI::MEDIA_TYPE)
56+
57+
parsed = JSON.parse(response.body)
58+
expect(parsed['errors'].first['detail']).to eq('Authentication failed')
5659
end
5760
end
5861

0 commit comments

Comments
 (0)